Jquery Match() IP Address?
Posted
by
user1635970
on Stack Overflow
See other posts from Stack Overflow
or by user1635970
Published on 2012-10-02T12:18:13Z
Indexed on
2012/10/08
9:37 UTC
Read the original article
Hit count: 157
I'm using a jquery script to validate form fields. This works well, but I'd like to change the validation of one field to check for IP Addresses.
The regex I want to use is :
\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
How do I amend the below to work with this ? (This is how the validation works for email address)
jQuery("#Email").validate({
expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
message: "Should be a valid Email id"
});
© Stack Overflow or respective owner