Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regular expression to validate domain name

Last post 02-09-2009, 1:48 AM by naz. 4 replies.
Sort Posts: Previous Next
  •  01-31-2009, 2:32 AM 50565

    Regular expression to validate domain name

    Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

    Hi guys!

    I'm using PL SQL in creation the regular expression. I use below expression to validate my domain name:

     

    ^(([a-z][0-9])|([0-9][a-z])|([a-z0-9][a-z0-9\-]{1,2}[a-z0-9])|([a-z0-9][a-z0-9\-](([a-z0-9\-][a-z0-9])|([a-z0-9][a-z0-9\-]))[a-z0-9\-]*[a-z0-9]))\.(com|my|org|net)\.my$

     

    The expression is ok. I can validate the value of double dot(..) and double dash(--). But i cannot validate the domain zone for .my (like free.my). 

    For your information I need to validation for zone of ".com.my",".org.my","net.my"  and ".my".

    How can i alter the expression to ensure that i can validate the .my zone?

     

     

  •  02-01-2009, 1:19 AM 50584 in reply to 50565

    Re: Regular expression to validate domain name

    I don't know if there is a special syntax used by PL SQL so the following may be way off base.

    I can't see how your pattern will validate a 'double dot' pattern because it seems to require (some seemingly quite bizarre)  sequence of alpha and numeric characters in all of the 4 main alternatives at the beginning of your pattern - no where does it include a dot except before the com|my|org|net options. Even there it would require one of those strings before the ".my" literal.

    Ditto for the 'double dash' as all 4 of the main options require either a leading alpha or leading numeric character.

    Finally, you have 'my' as one of the options before the final ".my" literal which would allow ".my.my" - do you mean that?

    If all you are interested in is that the string ends in ".my" then a simple

    \.my$

    should do it. If you want the validation you mention on the 2nd to last line, then

    \.(com|org|net)\.my$

    should do it - pretty much what you had without the subpattern at the beginning. 

    If I've got the wrong end of the stick, then I think you need to step back a bit and explain exactly what you are trying to do and provide us with examples that should both match and not match according to your criteria

    Susan

  •  02-01-2009, 4:23 AM 50589 in reply to 50584

    Re: Regular expression to validate domain name

    Hi Susan!

    Thanks for your response..For your information, i want to alter that regular expression to ensure that i can check the value of .my( for example to check naz.my). 

     Ok i explain my requirement to check the domain name

    1. Cannot enter ma--il.com.my (-- cannot be entered)  but (m-a-i-l.com.my can be entered) - means that cannot enter double dash(--)

    2. Cannot enter ma..il.com.my (-- cannot be entered)  but (m.a.i.l.com.my can be entered) - means that cannot enter double dot(..)

    3. Cannot enter the value of !@#$%^&*()+=?/><~`|\{}[] and [space]

    4. Can enter the value of - (dash) and . (dot)

    5. Can enter only alphanumeric only

    6. For the domain zone, need to validate for

           (i) .com.my (example: mail.com.my),

           (ii) .net.my  (example: mail.net.my),

           (iii)  .org.my  (example: mail.org.my),

           (iv) .name.my  (example: mail.name.my),

           (v) .my (mail.my)

         

     

  •  02-01-2009, 5:33 PM 50595 in reply to 50589

    Re: Regular expression to validate domain name

    naz,

    Repeating my comment about not knowing PL SQL so this may not work, my general approach to this would be:

    ^(?!.*?\.\.)(?!.*?--).*?\.(com|net|org|name)?\.my$

    The first 2 parts are lookaheads that make sure that there are no consecutive dots or spaces. The last parts allow for an optional ".com", ".net" or whatever and require the last part to be ".my".

    This is untested but may set you on the right track.

    Alternatively, if you can use 2 regex's and can negate the match in your code, then a regex that searches for

    --|\.\.

    will match if you have an invalid combination and you can then reject the text in your code based on that. The 2nd regex could then just test for the last one or two parts of the string as before.

    Susan 

  •  02-09-2009, 1:48 AM 50787 in reply to 50595

    Re: Regular expression to validate domain name

    thanks susan for your respond..i already get the solution..
View as RSS news feed in XML