1<!DOCTYPE html>
2<html>
3<head>
4 <title></title>
5</head>
6<body>
7<form method="post" action="">
8 Email:<input type="text" id="number" onkeyup="validation()">
9 </form>
10</body>
11<script type="text/javascript">
12 function validation(){
13 var number=document.getElementById("number").value;///get id with value
14 var numberpattern=/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/;////Regular expression
15 if(numberpattern.test(number))
16 {
17 document.getElementById("number").style.backgroundColor='yellow';
18 }
19 else
20 {
21 document.getElementById("number").style.backgroundColor='red';
22 }
23 }
24
25</script>
26</html>
1/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im
2
3//Valid Phone Numbers :
4(123) 456-7890
5(123)456-7890
6123-456-7890
7123.456.7890
81234567890
9+31636363634
10075-63546725
11