i need your javascript experties guys... can i validate an expression like this # numbers [(####)] ###[-]#### [loc ####] the optional [(####)] can be 2 - 4 numbers the optional [loc ####] can be 3 - 4 numbers i beleive i can do it on perl but i can't squeeze my brain on how to do it on javascript. thanks anyone. hope you could post some scripts... thansk again...
Bear Bibeault
Author and opinionated walrus
Marshal
I am guessing you wanted the brackets in it? So here is what I came up with. <script> var TheNum="[(111)] 111[-]1111[loc111]"; var ThePat = /^\[\(\d{3}\)\] \d{3}\[-\]\d{4}\[\d{2,4}\]$/; var ThePat2 = /^\[\(\d{3}\)\] \d{3}\[-\]\d{4}\[loc\d{3,4}\]$/; if(ThePat.test(TheNum) || ThePat2.test(TheNum) ){alert('match');} else alert('no'); </script>