PDA

View Full Version : How can I allow only certain domains in my text box and throw an alert if not ?



vardhamansai
Dec 2nd, 2015, 09:11 AM
I want to allow only few domains in my text field like :

http://www.abcd.yahoo.com
http://www.xyz.cnn.com
http://www.*.yahoo.com
http://www.*.cnn.com

If the user enters any other domain expect to the above formats , the script shall throw an error asking to re-enter once again ? How can I achieve this ?

Philip M
Dec 2nd, 2015, 10:17 AM
Suggest you use a drop-down select list so that only valid domains may be selected by the user.

If * is supposed to be a wildcard, then you can use a regular expression to allow only yahoo.com and cnn.com.

Note that alerts are regarded as obsolete. Prefer to use DOM methods to display a message to your users.