C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Javascript »

MobileNumber Validation using javascript


Posted Date: 01 Oct 2008    Resource Type: Code Snippets    Category: Javascript
Author: raviMember Level: Gold    
Rating: 1 out of 5Points: 5



This code shows how to validate a mobile number:

function ValidateMobileNumber(number)
{
MobileNumber=number.value
var ErrorMsg;
if (MobileNumber.length>10)
{
if(MobileNumber.length==12)
{
if(MobileNumber.substring(0,2)!="91")
{
ErrorMsg="Number should begin with 91";
}
else
ErrorMsg="";
}
else
{
ErrorMsg="Invalid Mobile Number ";
}
}
else
ErrorMsg="";
browserName = navigator.appName;
if (browserName =="Microsoft Internet Explorer")
{
lblMsg.innerText=ErrorMsg;
}
else
{
lblMsg.textContent=ErrorMsg;
}
if (ErrorMsg.length>0)
number.focus();

}




Responses

Author: Roopa Reddy    21 Nov 2008Member Level: Bronze   Points : 1
Ravi,

The code that you have written validates for 12 digit phone number that starts with 91. What if the user enters the input something like 9145456iiojj?


Author: Roopa Reddy    21 Nov 2008Member Level: Bronze   Points : 1
This will be useful for those looking for phone validation

http://www.smartwebby.com/DHTML/phone_no_validation.asp


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
MobileNumber Validation  .  Javascript  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Rounding number in javascript
Previous Resource: Javascript code to get browser details
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use