Javascript validation for Phone number, zipcode.

Posted by Joewilliam under JavaScript on 6/27/2011 | Points: 10 | Views : 4255 | Status : [Member] | Replies : 3
Zip code must accept 5-8 digits.
office phone should be in this format 0000-000000 000-00000000(3-5 to 6-8)

William Mary


Responses

Posted by: Jaganathan.eswaran on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Lot of validation expression rules available http://regexlib.com/

Be Simple & Sample

- Jagan B

Joewilliam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/27/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
For ZIP code use this regular expression
^[0-9]{5,8}$ 

And For Phone it will be
^(([0-9]{4}-[0-9]{6})|([0-9]{3}-[0-9]{8}))$.


You can use java script to perform validation.
Take a look at this
<script type="text/javascript">

function TestMatch() {
var val = document.getElementById('<%= TextBox1.ClientID %>').value;
var re = new RegExp("^[0-9]{5,8}$");
alert(re.test(val));
}
</script>




Joewilliam, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 6/28/2011 [Member] [MVP] Bronze | Points: 25

Login to post response