Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VbScript form validation for phone number, outlook email address formats

Posted on 2003-12-01
11
Medium Priority
?
1,116 Views
Last Modified: 2007-12-19
Hello,
I need some help regarding form validation of several items I have on a form.
Here is the pseudocode for the telephone format I want

if trim(request.querystring("tel")) does not fit the pattern (555) 555-5555 then      flag="error"
      response.write("Please enter a valid telephone number")
      response.write("<br>")
end if

Here is the pseudocode for the email format I want
*please note that the email I am checking for I only want to check that the address has a "," somewhere in the middle.

if trim(request.querystring("email")) does not fit the pattern AAA, AAA then      flag="error"
      response.write("Please enter a valid telephone number")
      response.write("<br>")
end if

thanks for all help
0
Comment
Question by:groovymonkey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 9850772
first one ( Phone), here is the code to handle it:

'this section ensures that you have enough characters in the field
if Request.Form("Phone).length != 13 then
   response.write "Please click back and enter a valid phone number: Format (###)###-####"
end if

'this section ensures that you have an opening -(- character and that it's at the beginning
if InStr(Request.Form("Phone"),"(")<>1 then
    response.write "Please click back and enter a valid phone number: Format (###)###-####
end if

'this section ensure that you have a -)- character and that it's at the 4th character
if InStr(Request.Form("Phone"),")")<> 4 then
    response.write "Please click back and enter a valid phone number: Format (###)###-####"
end if

'this section ensures that you have a - character and that it's at the 9th character
if InStr(Request.Form("Phone"), "-")<>9 then
    response.write "Please click back and enter a valid phone number: Format (###)###-####"
end if



second one, that the e-mail contains a ",":

if InStr(Request.Form("email"), ",") <=0 then
     response.write "Please click back and insert the 2nd address!"
end if


hope this helps!

MaxOvrdrv2
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 9850791
sorry sorry... the first if should be this instead:

if Length(Request.Form("Phone)) <> 13 then
   response.write "Please click back and enter a valid phone number: Format (###)###-####"
end if

MaxOvrdrv2
0
 

Author Comment

by:groovymonkey
ID: 9850893
Is there a way to do this using the pattern property in VbScript?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 9850991
using the pattern property in VBScript? -- This is an ASP forum, i would help you if i knew what you were talking about...

from that comment, i'm guessing that you are working in a .Net environment?

MaxOvrdrv2
0
 
LVL 1

Accepted Solution

by:
MikeVirtual earned 400 total points
ID: 9851451
<%

Dim objRegExp
Set objRegExp = New RegExp
objRegExp.Pattern = "\(\d{3}\)\d{3}\-\d{4}"
If objRegExp.Test(trim(request.querystring("tel"))) = False Then
 Response.Write("Please click back and enter a valid phone number: Format (###)###-####")
 Response.End()
Else

.........

Would suggest that you also use client side validation using javascript and similar regular expression.
Gimme a shout if you need the code.

Hope this helps
MikeVirtual
0
 
LVL 1

Expert Comment

by:MikeVirtual
ID: 9851495
By using javascript client side validation, you can simply remove any non-numeric characters, check you have 10 digits and, if so, reformat the text field accordingly, otherwise alert the user. This avoids a round trip to the server and the horrible 'back button' messsage.

Ask if you want the code.
MikeVirtual.
0
 

Author Comment

by:groovymonkey
ID: 9860435
Mike Virtual,
The vbscript worked great for the phone number...how would I do the same thing to check for an email to make sure that there is a comma somewhere in the middle?
0
 
LVL 1

Assisted Solution

by:MikeVirtual
MikeVirtual earned 400 total points
ID: 9860645
objRegExp.Pattern = "\w{3,},\w{3,}"

wil search for 3 or more word characters followed by a comma followed by 3 or more word characters

word characters are a-z, A-Z, 0-9 and _

If these are e-mail addresses, they will contain @ symbols and . character as well as possibly - characters

if so, I think

objRegExp.Pattern = "[\w\-\.]+@[\w\-\.]+\.[a-zA-Z]{2,4}"

should do the trick.

For more help on regular expressions see:

http://www.devguru.com/Technologies/vbscript/quickref/regexp_pattern.html

Hope this helps - if above regular expressiondoesn't do it, post a couple of examples of the strings you want to check
0
 
LVL 10

Expert Comment

by:MaxOvrdrv2
ID: 9860661
Mike... don't forget that it's obligatory for his users to put 2 addresses seperated by a comma, and that if there is no comma, an error should come up...

MaxOvrdrv2
0
 
LVL 1

Expert Comment

by:MikeVirtual
ID: 9860667
sorry,

objRegExp.Pattern = "[\w\-\.]+@[\w\-\.]+\.[a-zA-Z]{2,4},<?[\w\-\.]+@[\w\-\.]+\.[a-zA-Z]{2,4}>?"

or similar - depends what you are trying to parse

0
 
LVL 1

Expert Comment

by:MikeVirtual
ID: 9860683
MaxOvrdrv2 - noticed it soon as I hit send, doh!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question