Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7441721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:03:43+00:00 2026-05-29T11:03:43+00:00

The regex below works nice except I need only one dot (.) at the

  • 0

The regex below works nice except I need only one dot (.) at the end for nameserver. For example if user submit ns1.hello.com there will be error. Accepted format is with dot at the end like this ns1.hello.com. Help me please. Thank you.

    <script type="text/javascript">



function validSubdomain() {

    var re = /^[a-zA-Z0-9][a-zA-Z0-9.-]+\.$/;



    var val = document.getElementById("nameserver").value;

    var val2 = document.getElementById("nameserver2").value;



if(val == '' && val2 == ''){

     alert("Please fill in the name server"); 

     document.forms['namaform'].elements['nameserver'].focus();

     return false; 

} 



if(val == ''){

     alert("Please fill in the name server 1"); 

     document.forms['namaform'].elements['nameserver'].focus();

     return false; 

} 

if(val2 == ''){

     alert("Please fill in the name server 2"); 

     document.forms['namaform'].elements['nameserver2'].focus();

     return false; 

} 



var parts = val.split('.');

var parts2 = val2.split('.');

if (parts.length < 3) 

{ alert('invalid nameserver format') 

document.forms['namaform'].elements['nameserver'].focus();

return false;

}

else if (parts2.length < 3) 

{ alert('invalid nameserver 2 format') 

document.forms['namaform'].elements['nameserver2'].focus();

return false;

}









if( !re.test(val)) {

    alert("invalid nameserver 1 format");

    return false;

}

else if( !re.test(val2)) {

    alert("invalid nameserver 2 format");

}

else{namaform.submit();}







}

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:03:45+00:00Added an answer on May 29, 2026 at 11:03 am

    Two things wrong with:

    if(re.test(val && val2)) {  
        alert("valid format"); 
    } 
    if(!re.test(val && val2)) { 
        alert("invalid format"); 
    } 
    

    First of all, have you never heard of else? It’s there specifically so you don’t have to repeat a test in the negative.

    Second, you are trying to && together the two string and then passing the resulting boolean to re.test(). Since a boolean converts to the string "true" or "false" it will never ever match.

    Change to:

    if( re.test(val) && re.test(val2)) {
        alert("valid format");
    }
    else {
        alert("invalid format");
    }
    

    Also note that your regex is wrong. It would accept a..b as input, which is clearly not valid. Try this instead:

    var re = /^([a-z0-9-]+\.)+[a-z]{2,3}\.$/i;
    

    This will broadly match most domains with unlimited number of subdomain levels, provided there’s a . at the end.

    EDIT to disallow - at the front of a section:

    var re = /^([a-z0-9][a-z0-9-]*\.)+[a-z]{2,3}\.$/i;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regex to run against strings like the one below that will
the Javascript below only works as for youtube videos actual url. <script> regex =
I am white-belt regex. I have the following regex which sort of works except
Below is a regex which works fine in .net but give me error if
I need to split a string like the one below, based on space as
I need to validate the below range via regex in javascript. -20.00 to +20.00
I want to validate below data using regex and python. Below is the dump
How to find below comment block(s) with javascript/jquery regex: /* some description here */
Can anyone provide a regex for notepad++ for the below search and replace (conversion)
What regex pattern would need I to pass to java.lang.String.split() to split a String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.