Connecting Tech Pros Worldwide Help | Site Map

RegExp validation

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 11th, 2006, 09:35 AM
Andyza
Guest
 
Posts: n/a
Default RegExp validation

The following vbscript sub checks that a value has a specific format:
first 3 characters are alphabetic: anything from a - z. The last 4
characters are numeric: anything from 0 - 9

Sub CheckString(val)
Set VerifyValue = New RegExp
VerifyValue.Pattern = "^[a-z]{3}\d{4}$"
VerifyValue.IgnoreCase = True
If VerifyValue.Test(val) = False Then
alert("Please enter a valid number.")
End If
End Sub

How do I write this in JavaScript?


  #2  
Old May 11th, 2006, 09:55 AM
Vic Sowers
Guest
 
Posts: n/a
Default Re: RegExp validation


"Andyza" <andyza@webmail.co.za> wrote in message
news:1147339896.016959.301550@u72g2000cwu.googlegr oups.com...[color=blue]
> The following vbscript sub checks that a value has a specific format:
> first 3 characters are alphabetic: anything from a - z. The last 4
> characters are numeric: anything from 0 - 9
>
> Sub CheckString(val)
> Set VerifyValue = New RegExp
> VerifyValue.Pattern = "^[a-z]{3}\d{4}$"
> VerifyValue.IgnoreCase = True
> If VerifyValue.Test(val) = False Then
> alert("Please enter a valid number.")
> End If
> End Sub
>
> How do I write this in JavaScript?[/color]

function CheckString(val) {
if (!/^[a-z]{3}\d{4}$/i.test(val)) alert("Please enter a valid
number.");
}


  #3  
Old May 11th, 2006, 10:25 AM
Andyza
Guest
 
Posts: n/a
Default Re: RegExp validation

> function CheckString(val) {[color=blue]
> if (!/^[a-z]{3}\d{4}$/i.test(val)) alert("Please enter a valid
> number.");
> }[/color]

Man that was fast!

And it works perfectly too! Thanks.

  #4  
Old May 13th, 2006, 09:15 AM
Bogdan Blaszczak
Guest
 
Posts: n/a
Default Re: RegExp validation

Vic Sowers napisał(a):[color=blue][color=green]
>>
>>How do I write this in JavaScript?[/color]
>
>
> function CheckString(val) {
> if (!/^[a-z]{3}\d{4}$/i.test(val)) alert("Please enter a valid
> number.");
> }[/color]

or, to return boolean value

function CheckString(val,message){
return/^[a-z]{3}\d{4}$/i.test(val)||!!alert(message);
}


--
BlaTek
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.