Thursday, 25 July 2013

Phone Number Validation Using simple Javascript

Type Your Phone No.and Submit[Validation]


Here let's see the validation for  the phone number using simple javascript.Here is the script for the validation phoneno = /^\d{10}$/ . Using this script we can validate the phone number.Above is the live demo we can check by entering the alphabets and also numbers. By entering the alphabets we get the alert message as Not a valid Phone Number  and by entering the Number we can get the alert message as Your Phone Number have accepted : you can try another.

Download Coding :  Phonenumber Validation

Style :

<style type="text/css">
li {list-style-type: none;
font-size: 10pt;
.mail {
margin: auto;
padding-top: 10px;
padding-bottom: 10px;
width: 400px;
background : #CCC;
border: 1px soild silver;
.mail h2 {
margin-left: 68px;
input {
font-size: 15pt;
input:focus, textarea:focus{
background-color: lightyellow;
input submit {
font-size: 8pt;
.rq {
color: #FF0000;
font-size: 6pt;
.sub{margin-left:200px;width:100px; }

Script :

<script type="text/javascript">
function phonenumber(inputtxt)
  var phoneno = /^\d{10}$/;
            alert('Your Phone Number have accepted : you can try another');
            return true;
        alert("Not a valid Phone Number");
        return false;


Index :

<div class="mail">
Type Your Phone No.and Submit[Validation]</h2>
<form action="#" name="form1">
<li><input name="text1" type="text" /></li>
<li class="sub"><input name="submit" onclick="phonenumber(document.form1.text1)" type="submit" value="Submit" /></li>