Forums

ASP

This topic is locked

Vlidating data?

Posted 13 Mar 2002 12:30:21
1
has voted
13 Mar 2002 12:30:21 Bec C posted:
What is the syntax to validate data such as BS21 8FQ ??

I know in involves funny characters like ^ !!!!!

Both VB/Javascript would be handy.

Thanks

Replies

Replied 14 Mar 2002 22:03:28
14 Mar 2002 22:03:28 Joel Martinez replied:
well, that really depends on exactly what you are trying to validate... from what I gather, you need to make sure that the string is in this format [BS21 8FQ] correct?

then you could use a regular expression such as
/[^\d]{2}\d{2}.\d[^\d]{2}/gi

that will validate that you have this pattern
2 characters, 2 digits, 1 space, 1 char, and 2 digits.

you can then test it this way <pre id=code><font face=courier size=2 id=code>function checkstr(str)
{
var patt = /[^\d]{2}\d{2}.\d[^\d]{2}/gi;
return str.test(patt);
}</font id=code></pre id=code>I think that's the right syntax... sorry I didn't give you a vbscript version, but I don't like the regexp syntax in vbscript, much prefer js.

Joel Martinez
MX inSite Magazine
The Complete Resource for Macromedia designers & developers
Sign up for your free electronic Preview Issue
www.mxinsite.com

Reply to this topic