Home · Latest · Trends  /  JavaScript
2

Validating international phone numbers

rated 2 times [  2] [ 0]  / comments: 1 / hits: 1227  / 2 years ago, sun, sep 25, 2016, 14:52:42
Validating international phone numbers with jquery
<!DOCTYPE html>
<html> 
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<input type="text" id="number" name="phonenumber" />
<script>
jQuery('#number').keyup(function () { 
this.value = this.value.replace(/[^0-9.s+()]/g,'');
});
</script>
</body>
</html>
More From » JavaScript
 

Comments

3
You may use this..
Code:
<!DOCTYPE html>
<html> 
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<input type="text" id="number" name="phonenumber" />
<script>
jQuery('#number').keypress(function(e) {
var numbersTyped = String.fromCharCode(e.which);
if (/[^0-9.s+()]/i.test(numbersTyped)) {
 alert("This is not valid phone number. Please enter the phone number in format +12144454567");
 $("#number").val('');
 return false;
}
if($(this).val().length >= 12) {
 $(this).val($(this).val().slice(11, 12));
 alert("This is not valid phone number. Please enter the phone number in format +12144454567");
 $("#number").val('');
 return false;
}
});
jQuery('.numbersOnly').keyup(function () { 
this.value = this.value.replace(/[^0-9\.]/g,'');
});
</script>
</body>
</html>
[#1] Sunday, September 25, 2016, 16:14:56
 
James
commented 2 years ago
Only authorized users can post. Please sign in first, or register a free account
 
Share
Snippets
Using bind variables with ADODB
3 years ago, tue, sep 6, 2016
This module provides HTML and CLI interfaces for viewing key performance indicators of your database.
3 years ago, tue, sep 6, 2016
How to check if mail function is enabled on your server
3 years ago, tue, sep 6, 2016
Compare dates in smarty template file
2 years ago, fri, sep 16, 2016
Change default chrome input style CSS
2 years ago, fri, sep 16, 2016
Get domain name without Tld with PHP
2 years ago, fri, sep 16, 2016
Smarty Remove BBCode From String
2 years ago, thu, nov 10, 2016
How to detect if uploaded file is image or not with php
2 years ago, mon, nov 21, 2016
How to check CKEditor 4 textarea not empty
2 years ago, sun, dec 25, 2016
Posted
Ronald

Ronald

Member since Sep 6, 2016
Total Code Snippets: 20
Total Comments: 1
Location: n/a
Following
User not following anyone yet.