groovymonkey
asked on
VbScript form validation for phone number, outlook email address formats
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
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("
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("
response.write("Please enter a valid telephone number")
response.write("<br>")
end if
thanks for all help
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
if Length(Request.Form("Phone
response.write "Please click back and enter a valid phone number: Format (###)###-####"
end if
MaxOvrdrv2
ASKER
Is there a way to do this using the pattern property in VbScript?
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
from that comment, i'm guessing that you are working in a .Net environment?
MaxOvrdrv2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Ask if you want the code.
MikeVirtual.
ASKER
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?
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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
MaxOvrdrv2
sorry,
objRegExp.Pattern = "[\w\-\.]+@[\w\-\.]+\.[a-z A-Z]{2,4}, <?[\w\-\.] +@[\w\-\.] +\.[a-zA-Z ]{2,4}>?"
or similar - depends what you are trying to parse
objRegExp.Pattern = "[\w\-\.]+@[\w\-\.]+\.[a-z
or similar - depends what you are trying to parse
MaxOvrdrv2 - noticed it soon as I hit send, doh!
'this section ensures that you have enough characters in the field
if Request.Form("Phone).lengt
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"
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"
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"
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"
response.write "Please click back and insert the 2nd address!"
end if
hope this helps!
MaxOvrdrv2