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 »

Regular Expressions


Posted Date: 30 Jul 2009    Resource Type: Code Snippets    Category: Javascript
Author: gomathinayagamMember Level: Gold    
Rating: 1 out of 5Points: 7



Description :


This code shows how to validate in javascript with keycode which is some how difficult so we can use regular expression to test email and phone number etc with only 2 lines of code.


A period ( . ) represents any character except a newline.
Backslash-d ( \d ) represents any digit.
Backslash-D ( \D ) represents any character except a digit.
Backslash-w ( \w ) represents any word character.
Backslash-W ( \W ) represents any character except a word character.
Backslash-s ( \s) represents any whitespace character.
Backslash-S ( \S ) represents any character except a whitespace character.



function validate(input)
{
var email=/^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;
var numberonly =/\d/;
var notanumber =/\D/;

if(numberonly.test(input))
{
alert("number");
}
if(notanumber.test(input))
{
alert("not a number");
}

if(email.test(input))
{
alert("valid email");
}

}



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Javascript validation  .  Javascript regular expression  .  Javascript email validation  .  

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: Javascript validations for a Textbox
Previous Resource: Copying Gridview Data using javascript
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use