473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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?

May 11 '06 #1
3 1320

"Andyza" <an****@webmail.co.za> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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?


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


Man that was fast!

And it works perfectly too! Thanks.

May 11 '06 #3
Vic Sowers napisał(a):

How do I write this in JavaScript?

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


or, to return boolean value

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: phal | last post by:
Hi all; I code Perl for CGI, I using regular expression to check the validation of user input, because the form is small and it run only from my own computer, anyways if many people using my...
3
by: jasonkester | last post by:
Just a heads up for anybody that comes across this in the future. Noticed a strange behavior in RegExp.test() today. Check out the following code. It will alternately display "chokes" and null,...
12
by: Dag Sunde | last post by:
My understanding of regular expressions is rudimentary, at best. I have this RegExp to to a very simple validation of an email-address, but it turns out that it refuses to accept mail-addresses...
8
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
6
by: Edward | last post by:
I need to validate a text box entry, but ONLY if it is 17 characters, otherwise I have to ignore it. My regular expression for the validation is: ^(({9})()()(\d{6}))$ Can I adapt this to...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
6
by: Christoph | last post by:
I'm trying to set up client side validation for a textarea form element to ensure that the data entered does not exceed 200 characters. I'm using the following code but it doesn't seem to be...
3
by: c676228 | last post by:
Hi everyone, I just realized that it's so important to validate each string, I mean 'each' before you insert data from asp page into database. I guess some customers just copy data from some...
5
by: paulmcnally | last post by:
Hi, I need a javascript RegExp for image file validation from a file upload form. I need to allow image files only (jpeg/jpg/gif/png) can anybody help me please? thanks,
1
by: bdbeames | last post by:
I have a form where I would like to perform some validation using a javascript function. I cant' figure out the RegExp. function is_number(target) { target.value = trim(target.value); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.