Sunday, January 18, 2009

JS: Javascript with Regular Expression

This following sample will help you, how to use Regular Expression concept in Javascrtipt.In this Code, pattern is defined to validate the text content should start with "a" and 5 digit number.For Example:a00000



function validateValue()
{

// Defining Regular Expression Pattern
// This Pattern is validate the value like "a00000"
var re5digit = /^\a\d{5}$/

if (document.form1.TextBox1.value.search(re5digit) == -1) //if match failed
alert("Please enter a valid 5 digit number inside the text starts with 'a', Example: a00000")
}

No comments:

Post a Comment