validating value using regular expression in javascript

In this tutorial I will show you how can we validate value using regular expression in javascript.
Fist we need to take value in on variable.

var myValue = document.getElementById("MyTextbox;

& my regEx is

var myRegEx = /[^0-9]/;

Now there are two ways to do validation of value with regular Expression

1. Using “Search” property of value i.e.

var result = myValue.value.search(myRegEx);

value of result will be either 0 if value passes regular expression check or -1 if value fails regular expression check.

2. using “test” property i.e.

var result = myRegEx.test(myValue);

value of result will be either true if value passes regular expression check or false if value fails regular expression check.

admin