Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check for numbers/letters in a string 1

Status
Not open for further replies.

vivasuzi

Programmer
Jun 14, 2002
183
I have a form, and when it is submitted, I want to check that all text fields (name, city, state) are only letters, and all number fields (phone, zip) are only numbers. Is there some quick way to check that a field has only letters or only numbers?

I also want to be able to check that the fields don't have any chars besides letters and numbers.

I don't need a function written for me, I was hoping there was something in asp to do this. Any help is welcome :) *Suzanne*
 
try a search for regular expression alphanumeric validation
the patterns will be very basic and it will be a efficient way to do this onpnt
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
 
You can use the Regular Expression object to do pattern matching if you like. See the following article on 4guysfromrolla.com


You might be able to use the Instr function to see if any certain character is within (or not within) your value ________________________________________________________________________
Are you trying to debug your ASP applications? See faq333-3255 for more details

regards,
Brian
 
Well onpnt, I guess we were thinking the same thing at the same time....: ) ________________________________________________________________________
Are you trying to debug your ASP applications? See faq333-3255 for more details

regards,
Brian
 
Okay except, I couldn't figure out what the regular expression would be for a space. Since cities can have a space in them, what would I write? I saw that \s recognizes "whitespace" but that includes tabs and things I don't want to include. Any suggestions?
*Suzanne*
 
how about taking them out???? onpnt
_________________________________________________________
for the best results to your questions: FAQ333-2924
Is your question a most FAQ?? Find out here FAQ333-3048
onpnt2.gif
 
One more question. I'm trying to validate an email address. Is this a good way to do it or should I just use javascript? I'm not sure how to make the regular expression for that though. I tried something like

\w@\w.\w

but that didn't work. I think I just made that up :) But if you already know how to do it, or where I can look for how to do it, then any help is always welcome :) thanx. *Suzanne*
 
There are a lot of sample regular expreszsion strings out there for things like validation of email or domain addresses.
Here is a link to validating email addresses using javascript or VBScript:
Also, to answer your earlier question, the space is not a special character in regular expressions, so though it looks wierd you can simply put a space in your expression for it to match spaces:
Code:
myRegExp.pattern = "abcd +dcba"
That will match a portion of a string that starts with abcd, has 1 or more spaces, and ends in dcba.

-Tarwn ________________________________________________
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
This regular expression works for me.
"^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top