Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Validation for phone numbers

Tags:

html

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

like image 330
Jayashree venugopal Avatar asked Jun 21 '16 05:06

Jayashree venugopal


People also ask

How do you validate a phone number in HTML?

The <input type="tel"> defines a field for entering a telephone number. Note: Browsers that do not support "tel" fall back to being a standard "text" input. Tip: Always add the <label> tag for best accessibility practices!

How do you validate a phone number input field?

Validate a Phone Number Using a JavaScript Regex and HTMLfunction validatePhoneNumber(input_str) { var re = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/; return re. test(input_str); } function validateForm(event) { var phone = document.

How do you write a phone number validation?

Allow a leading “1” In addition to the phone number formats shown previously, this regular expression will also match strings such as +1 (123) 456-7890 and 1-123-456-7890 . It uses a noncapturing group, written as ‹ (?:⋯) ›.

How do you write validation in HTML?

The simplest HTML validation feature is the required attribute. To make an input mandatory, add this attribute to the element. When this attribute is set, the element matches the :required UI pseudo-class and the form won't submit, displaying an error message on submission when the input is empty.


1 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

like image 104
John3136 Avatar answered Oct 24 '22 10:10

John3136