javascript - regular expression for wildcard domain validation -


I am new to writing regular expressions I am planning to write regular expressions to validate wildcard domain mailing . Here are the scenarios.

Correct:

  • *. Test.com
  • test.com
  • abc.test.com

    Wrong:

    • * Test Com
    • test.com *
    • test. Com
    • test.abc * .com

      My regular expression for the above secnario

       [One-zA-Z0-9]) \ [+ A-zA-Z] {2,6} $ /   

      Is it working as expected? Do we have better expressions Can improve or write?

        ^ (\ *.)? ([\ W -] + \.) + [\ W -] + $   

      matches your examples.

      From my point of view, I also consider the third negative example correct.

        ^ (([\ w -] + \.) | (\ *.)) + [\ W -] + $   

      < / P>

      Edit:
      You may have to customize the character squares to include the allowed characters. I wanted to keep Rizax easy to read

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -