<input type="text" name="country_code" title="Error Message" pattern="[1-9]{1}[0-9]{9}">
This will ensure
- It is numeric
- It will be max of 10 chars
- First digit is not zero
AbstractAPI
abstractapi.com › api guides, tips & tricks › 10 digit phone number validation
10-Digit Phone Number Validation: Best Practices & Tools - Abstract
July 24, 2025 - Validating phone numbers is a crucial step in ensuring data accuracy and user experience. This guide has covered: The structure of U.S. 10-digit phone numbers. Maximum length constraints for validation. Common mistakes and how to avoid them. Excel-based validation techniques. Standardized phone number formatting. Technical implementation using JavaScript, Python, and HTML5...
W3Schools
w3schools.in › javascript › validate-a-phone-number
JavaScript Phone Number Validation - W3Schools
<script> // Validate phone number function function validatePhoneNumber() { // Get and trim phone number input const phoneNumber = document.getElementById('phoneNumber').value.trim(); // Regex pattern for 10-digit phone number const pattern = /^\d{10}$/; // Validate phone number and update ...
Top answer 1 of 11
5
Above code is correct but mobile validation is not perfect.
i modified as
$('#enquiry_form').validate({
rules:{
name:"required",
email:{
required:true,
email:true
},
mobile:{
required:true,
minlength:9,
maxlength:10,
number: true
},
messages:{
name:"Please enter your username..!",
email:"Please enter your email..!",
mobile:"Enter your mobile no"
},
submitHandler: function(form) {alert("working");
//write your success code here
}
});
2 of 11
4
for email validation, <input type="email"> is enough..
for mobile no use pattern attribute for input as follows:
<input type="number" pattern="\d{3}[\-]\d{3}[\-]\d{4}" required>
you can check for more patterns on http://html5pattern.com.
for focusing on field, you can use onkeyup() event as:
function check()
{
var mobile = document.getElementById('mobile');
var message = document.getElementById('message');
var goodColor = "#0C6";
var badColor = "#FF9B37";
if(mobile.value.length!=10){
mobile.style.backgroundColor = badColor;
message.style.color = badColor;
message.innerHTML = "required 10 digits, match requested format!"
}}
and your HTML code should be:
<input name="mobile" id="mobile" type="number" required onkeyup="check(); return false;" ><span id="message"></span>
Top answer 1 of 2
2
You can try below script to validate , 10 digits phone number, · function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; }var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/; · if(!pattern.test(newValue)){ g_form.clearValue('');g_form.showFieldMsg('', 'Please enter a valid Phone number', 'error');};}
2 of 2
1
Hello, · You can try something like this: · function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } · var oldV = oldValue; var validRegExp = /^\(?(\d{3})\)?[ -]?(\d{3})[ -]?(\d{4})$/; var checkPhone = g_form.getValue('phone_number_requested_for'); if (checkPhone.search(validRegExp) == -1) { alert('Enter valid mobile phone in : (999) 999-9999, 999-999-9999, and 9999999999 formats'); g_form.setValue('phone_number_requested_for',oldV); }} · · Regards, · Kalyani Shaha
Top answer 1 of 3
3
Try this one this will work, same i used for my client
<div class="form-group">
<label for="phone">Enter your phone number:</label>
<input type="text" class="form-control" title="please enter a valid phone number" pattern="^(\+91[\-\s]?)?[0]?(91)?[6789]\d{9}$" oninput="if (typeof this.reportValidity === 'function') {this.reportValidity();}" />
</div>
2 of 3
1
As per my comment above, try this:
<div class="form-group">
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" placeholder="+910123456789 or 0123456789" pattern="[+0-9]{10,13}">
</div>
You can test Regex here: https://regex101.com/
function displayInputValue() {
console.log(document.querySelector("input[type='tel']").value)
}
<div class="form-group">
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" placeholder="+910123456789 or 0123456789" pattern="[+0-9]{10,13}">
<button type="button" onClick="displayInputValue()">Show Value</button>
</div>
Digittrix Infotech
digittrix.com › scripts › email-and-phone-number-validation-in-html-and-javascript
Email and Phone Number Validation in HTML and JavaScript
June 17, 2025 - <script> const form = document.getElementById('contactForm'); const email = document.getElementById('email'); const phone = document.getElementById('phone'); const emailError = document.getElementById('emailError'); const phoneError = document.getElementById('phoneError'); form.addEventListener('submit', function(e) { e.preventDefault(); emailError.textContent = ''; phoneError.textContent = ''; const emailPattern = /^[^ ]+@[^ ]+\.[a-z]{2,}$/i; const phonePattern = /^\+?\d{10,14}$/; let valid = true; if (!emailPattern.test(email.value)) { emailError.textContent = 'Invalid email format.'; valid
Squash
squash.io › how-to-match-standard-10-digit-phone-number-with-regex
How To Match Standard 10 Digit Phone Numbers With Regex
September 1, 2023 - These patterns or functions are ... For example, in JavaScript, you can use the pattern attribute with the value "[0-9]{10}" in an HTML input element to enforce a 10-digit phone number....
Tech Solution Stuff
techsolutionstuff.com › post › how-to-validate-10-digit-mobile-number-using-regular-expression
How To Validate 10 Digit Mobile Number Using Regular Expression
March 30, 2024 - When we are working with form validation at that time you need to restrict user to enter invalid value and users allow only numeric value or valid number. So let's see regular expression for 10 digit mobile number ... <html> <head> <title>How To Validate 10 Digit Mobile Number Using Regular ...