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

0

3 Answers 3

38

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

Sign up to request clarification or add additional context in comments.

2 Comments

can we add two kinds of pattern for the same field,ie user can either enter a phone number with a '+' or a number?
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.
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

1 Comment

type="tel" does not automatically validate telephone number though. See MDN Docs. Regex is what I would suggest to OP too.
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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.