HTML5 Form validation is another type of client side validation . In HTML5 validation no javascript or jquery needed. Using HTML5 we can validate form with pattern.
Different type of Pattern Matching in HTML5
- Letter only
- Number only
- Password
- Phone no
- Alphanumeric
- URL
Letters Only
pattern=”[A-Za-z]+” accepts only capital or small letters.
pattern=”[A-Za-z]+” accepts only capital or small letters.
Number only
pattern=”[0-9]+” accepts only numbers 0, 1, 2….
pattern=”[0-9]+” accepts only numbers 0, 1, 2….
Email
pattern=”[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$” accepts valid email address
pattern=”[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$” accepts valid email address
Password
pattern=”(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}” accept at least one number and one uppercase and lowercase letter, and at least 6 or more characters
pattern=”(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}” accept at least one number and one uppercase and lowercase letter, and at least 6 or more characters
Phone no
pattern=”^d{10}$” accepts only numeric values with 10 digit.
pattern=”^d{10}$” accepts only numeric values with 10 digit.
Alphanumeric
pattern=”^[a-zA-Z][a-zA-Z0-9-_.]{5,12}$” accepts alphanumeric values letters and digits.
pattern=”^[a-zA-Z][a-zA-Z0-9-_.]{5,12}$” accepts alphanumeric values letters and digits.
URL
pattern=”https?://.+” required title=”http://phpgurukul.com” accepts valid web url starting with http://.
pattern=”https?://.+” required title=”http://phpgurukul.com” accepts valid web url starting with http://.
1
2
3
4
|
<form>
<input type="url" name="website" pattern="https?://.+" required title="http://phpgurukul.com" />
<input type="submit" />
</form>
|
0 Comments