14

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 Answers3

37

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

John3136
  • 28,809
  • 4
  • 51
  • 69
  • can we add two kinds of pattern for the same field,ie user can either enter a phone number with a '+' or a number? – Jayashree venugopal Jun 21 '16 at 09:11
  • You can modify the pattern regex to make the + optional. Plenty of hits on google for it. If the answer helped please upvote or accept. – John3136 Jun 21 '16 at 11:18
0

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/

HTML5 phone number validation with pattern

HTML5 Email Validation

Community
  • 1
  • 1
Clement Amarnath
  • 5,301
  • 1
  • 21
  • 34
0

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>