phone number validation javascript
My regex of choice is:
/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im
Valid formats:
(123) 456-7890
(123)456-7890
123-456-7890
123.456.7890
1234567890
+31636363634
075-63546725function telephoneCheck(str) {
var regex = /^(1\s?)?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{4}$/;
return regex.test(str);
}<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="">
Email:<input type="text" id="number" onkeyup="validation()">
</form>
</body>
<script type="text/javascript">
function validation(){
var number=document.getElementById("number").value;///get id with value
var numberpattern=/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;////Regular expression
if(numberpattern.test(number))
{
document.getElementById("number").style.backgroundColor='yellow';
}
else
{
document.getElementById("number").style.backgroundColor='red';
}
}
</script>
</html>/^\d{10}$/
Also in JavaScript:
- Javascript clear canvas
- js event listener mouseover
- pegar qual domínio eu estou javascript
- javascript toggle variable
- c# parse json
- javascript count digits
- pick equivalen in es6
- ion button transparent
- JS how to determine if page was cached
- how can node js file be serve
- how to create a new react native project
- SQL Developer store procedure insert json file to blob
- js click anchor
- change js to json
- filter keys from object using ramda
- how to find dates in a string in js
- js byte size
- com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON
- concat array javascript
- check if string contains substring javascript
- get count of class which is visible element
- screen.render is not a function in node
- typed js
- sort by ascending javascript