Validation patterns can be added to form fields like a phone number or email address so that it accepts the number or email if it matches the set pattern.
Here are some sample patterns:
Phone: <input type="text" name="Phone Number" pattern="[7-9]{1}[0-9]{9}"
This would only accept 10 digits and the first number should start with 7,8 or 9 and then the remaining 9 numbers could be anything between 0 and 9. This is a format that works for Indian numbers.
Sample Email Validation pattern:
function validateEmail(elementValue){
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return emailPattern.test(elementValue);
}
This would only accept an email address that starts with any uppercase or lowercase alphabets and numbers and has @ and then allows alphabets and numbers and 2 to 4 characters after the period (.). This is to separate domain and subdomain names.