I am new to HTML,can any one please help me to validate a phone number only with '+' and numeric values and phone number shud not exceed 13 numbers,and to validate email with a '@' and a '.',I dont want to use javascript
3 Answers
In HTML5 you can use <input type='tel'> and <input type='email'>
You can also specify a specific pattern like <input type='tel' pattern='[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}' title='Phone Number (Format: +99(99)9999-9999)'>
Something like pattern='^\+?\d{0,13}' Would give you an optional + and up to 13 digits
2 Comments
Email Validation - <input type="email" />, use the type as email.
Telephone number validation - <input type="tel" />. use the type as tel.
Reference:
https://www.sitepoint.com/client-side-form-validation-html5/
HTML and/or JavaScript will only validate email on client side, the more secure solution would be to validate email on the server side. Having said that you can do basic validation in HTML 5 like
<form> <input type="email" placeholder="Your email" required> <input type="submit" value="Submit"> </form>