-
Validating domain name with struts validator (4 messages)
- Posted by: Manish Hatwalne
- Posted on: June 23 2006 04:16 EDT
Can anyone help me write proper validation for validating a domain name (only SLD), I am trying few things wit RegEx but guess I am not very comfortable with regular expressions now. The conditions for valid domain mae are as follow - * Domain Name must be composed of the letters a through z, the numbers 0 through 9, and the hyphen (-) character. * The Domain Name must not begin or end with the hyphen character. * The Domain Name must not contain spaces. * The Domain Name must not contain special characters other than the hyphen character. * The Domain Name must contain 2 to 63 characters, inclusive. * Domain Names are not case sensitive. What should I put in this mask now considering the conditions mentioned above? mask ???????? TIA, - ManishThreaded Messages (4)
- Re: Validating domain name with struts validator by Bob Armour on June 23 2006 05:39 EDT
- Re: Validating domain name with struts validator by Manish Hatwalne on June 23 2006 08:57 EDT
-
Re: Validating domain name with struts validator by Bob Armour on June 26 2006 10:58 EDT
- Re: Validating domain name with struts validator by Manish Hatwalne on June 26 2006 11:32 EDT
-
Re: Validating domain name with struts validator by Bob Armour on June 26 2006 10:58 EDT
- Re: Validating domain name with struts validator by Manish Hatwalne on June 23 2006 08:57 EDT
-
Re: Validating domain name with struts validator[ Go to top ]
- Posted by: Bob Armour
- Posted on: June 23 2006 05:39 EDT
- in response to Manish Hatwalne
The following regexp will cover everything but the length check, which can be done by adding minlength and maxlength clauses to the validation rule (Covered in the validator docs). ^([a-zA-z0-9]{2,})(-([a-zA-Z0-9]+))*$ -
Re: Validating domain name with struts validator[ Go to top ]
- Posted by: Manish Hatwalne
- Posted on: June 23 2006 08:57 EDT
- in response to Bob Armour
Thanks!!! It almost works perfect, but it takes an uderscore as a vaild inpits which is incorrect. Besides alpha-numeric characters, I only want hyphen to be accepted. - Manish -
Re: Validating domain name with struts validator[ Go to top ]
- Posted by: Bob Armour
- Posted on: June 26 2006 10:58 EDT
- in response to Manish Hatwalne
Hmmm, Oops, I made a slight typing mistake in the original regular expression - the second 'z' should be uppercase. The typo means that anything between uppercase 'A' and lowercase 'z' will be allowed in the section before the first '.' - and this would include any of the following characters... [\]^_` My apologies for any extra time that you wasted looking for my typo. Just for the record, here is a link to a great tool that allows you to do 'what-if' experiment with regular expressions, this really helps you to practice using them - something that you should be doing because they really do make you code easier to read (and adjust) http://www.weitz.de/regex-coach/ Enjoy! -
Re: Validating domain name with struts validator[ Go to top ]
- Posted by: Manish Hatwalne
- Posted on: June 26 2006 23:32 EDT
- in response to Bob Armour
Thanks a ton for the useful link! :) - Manish