Following are example of JavaScript Validation Function and useful patterns.
JavaScript Function
JavaScript Function
function ClientValidate(str) {
var pattern = new RegExp("^[a-zA-Z0-9]+$");
return pattern.test(arguments.Value);
}
Any characters and number. No special characters.
var pattern = new RegExp("^[a-zA-Z0-9]+$");
Numeric number only
var pattern = new RegExp("^[0-9]+$");
Email Validataion
var pattern = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");
//ex. matinee.la@mymail.office
//ex. matinee.la@yahoo.com
Phone Number
var pattern = new RegExp("^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d+))*$");
0 comments:
Post a Comment