Reputation: 244
I want to create a regular expression for DNS.
My requirement is that the valid DNS should be:
Only 4 dots(.
) are allowed. I have tried this regular expression but its not working. Please suggest.
^[a-zA-Z0-9]+.[a-zA-Z0-9]+.[a-zA-z0-9]+.[a-zA-z0-9]$
Upvotes: 1
Views: 2430
Reputation: 3711
try this link
Regular expression to match DNS hostname or IP Address?
http://www.regexplanet.com/advanced/java/index.html
Upvotes: 1
Reputation: 17621
A very simple regex could be something along
^www\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+(\.[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)?)?$
Three points:
.
) is a special character and must be escaped (\.
)www
, so you need to include this in order to use the start mark (^
)Upvotes: 1