Validate multiple form fields with one method

N

Neo Geshel

Greetings,

I have a form with a telephone field. It is very specific, as it has
four text boxes - the country code, area code, prefix and suffix. I can
validate each of them individually, but I am stumped as to how to
validate them as a group (as one final validation). I need to check to
see if all (at one time) are filled or empty. The other individual
validations handle cases where the text boxes are filled with letters or
incompletely filled (I simply use a regular expression that checks for
an exact number of integers). However, I need to check if the entire
phone field has been filled or left empty.

One way I did it with PHP was to string all the fields together, then
run an if-else that first checked if the entire string was 12 integers
long, or if it was less than or equal to 2 integers long (the default
country code of 01). If it was the former, then the phone number was OK.
If it was the latter, there was no phone number inputted, and it could
be ignored. And if it was somewhere in-between or failed the regex, the
validation failed and the error message would be displayed.

Is there any method that anyone might suggest to do it as I did it in
PHP? I am hoping to have it done alongside the normal form validation,
so that the

if (Page.IsValid){}

can run as normal and be affected as appropriate from a badly formed
phone number.

TIA
...Geshel
--
*********************************************************************
My return e-mail address is an automatically monitored spam honeypot.
Do not send e-mail there unless you wish to be reported as a spammer.
Please send all e-mail to my first name at my last name dot org, with
a subject-line of “NEWSGROUP REPLY FOR NEO GESHEL†(all uppercase).
*********************************************************************
 
G

Guest

Greetings,

I have a form with a telephone field. It is very specific, as it has
four text boxes - the country code, area code, prefix and suffix. I can
validate each of them individually, but I am stumped as to how to
validate them as a group (as one final validation). I need to check to
see if all (at one time) are filled or empty. The other individual
validations handle cases where the text boxes are filled with letters or
incompletely filled (I simply use a regular expression that checks for
an exact number of integers). However, I need to check if the entire
phone field has been filled or left empty.

One way I did it with PHP was to string all the fields together, then
run an if-else that first checked if the entire string was 12 integers
long, or if it was less than or equal to 2 integers long (the default
country code of 01). If it was the former, then the phone number was OK.
If it was the latter, there was no phone number inputted, and it could
be ignored. And if it was somewhere in-between or failed the regex, the
validation failed and the error message would be displayed.

Is there any method that anyone might suggest to do it as I did it in
PHP? I am hoping to have it done alongside the normal form validation,
so that the

if (Page.IsValid){}

can run as normal and be affected as appropriate from a badly formed
phone number.

TIA
...Geshel
--
*********************************************************************
My return e-mail address is an automatically monitored spam honeypot.
Do not send e-mail there unless you wish to be reported as a spammer.
Please send all e-mail to my first name at my last name dot org, with
a subject-line of "NEWSGROUP REPLY FOR NEO GESHEL" (all uppercase).
*********************************************************************

1) Using standard validation controls you can perform it with
individual RegularExpressionValidators

e.g.

Private function ValidateFormValues()

CountryCode = Request("CountryCode")
AreaCode = Request("AreaCode")
Prefix = Request("Prefix")
Suffix = Request("Suffix")

strValidationMessage = strValidationMessage &
RegularExpressionValidator(CountryCode, "CountryCode", "[0-9]{2}")
strValidationMessage = strValidationMessage &
RegularExpressionValidator(AreaCode, "AreaCode", "[0-9]{4}")
strValidationMessage = strValidationMessage &
RegularExpressionValidator(Prefix, "Prefix", "[0-9]{4}")
strValidationMessage = strValidationMessage &
RegularExpressionValidator(Suffix, "Suffix", "[0-9]{3}")

' Check to see if errors occurred.
if len( strValidationMessage ) < 1 then
ValidateFormValues = True
else
ValidateFormValues = False
end if

end function

2) using custom code

CountryCode = Request("CountryCode")
AreaCode = Request("AreaCode")
Prefix = Request("Prefix")
Suffix = Request("Suffix")

Phone = CountryCode & AreaCode & Prefix & Suffix

if Not Regex.IsMatch(Phone,"[0-9]{2}[0-9]{4}[0-9]{4}[0-9]
{3}",RegexOptions.IgnoreCase) then
.....
 
N

Neo Geshel

Alexey said:
Greetings,

I have a form with a telephone field. It is very specific, as it has
four text boxes - the country code, area code, prefix and suffix. I can
validate each of them individually, but I am stumped as to how to
validate them as a group (as one final validation). I need to check to
see if all (at one time) are filled or empty. The other individual
validations handle cases where the text boxes are filled with letters or
incompletely filled (I simply use a regular expression that checks for
an exact number of integers). However, I need to check if the entire
phone field has been filled or left empty.

One way I did it with PHP was to string all the fields together, then
run an if-else that first checked if the entire string was 12 integers
long, or if it was less than or equal to 2 integers long (the default
country code of 01). If it was the former, then the phone number was OK.
If it was the latter, there was no phone number inputted, and it could
be ignored. And if it was somewhere in-between or failed the regex, the
validation failed and the error message would be displayed.

Is there any method that anyone might suggest to do it as I did it in
PHP? I am hoping to have it done alongside the normal form validation,
so that the

if (Page.IsValid){}

can run as normal and be affected as appropriate from a badly formed
phone number.

TIA
...Geshel
--
*********************************************************************
My return e-mail address is an automatically monitored spam honeypot.
Do not send e-mail there unless you wish to be reported as a spammer.
Please send all e-mail to my first name at my last name dot org, with
a subject-line of "NEWSGROUP REPLY FOR NEO GESHEL" (all uppercase).
*********************************************************************

1) Using standard validation controls you can perform it with
individual RegularExpressionValidators

e.g.

Private function ValidateFormValues()

CountryCode = Request("CountryCode")
AreaCode = Request("AreaCode")
Prefix = Request("Prefix")
Suffix = Request("Suffix")

strValidationMessage = strValidationMessage &
RegularExpressionValidator(CountryCode, "CountryCode", "[0-9]{2}")
strValidationMessage = strValidationMessage &
RegularExpressionValidator(AreaCode, "AreaCode", "[0-9]{4}")
strValidationMessage = strValidationMessage &
RegularExpressionValidator(Prefix, "Prefix", "[0-9]{4}")
strValidationMessage = strValidationMessage &
RegularExpressionValidator(Suffix, "Suffix", "[0-9]{3}")

' Check to see if errors occurred.
if len( strValidationMessage ) < 1 then
ValidateFormValues = True
else
ValidateFormValues = False
end if

end function

2) using custom code

CountryCode = Request("CountryCode")
AreaCode = Request("AreaCode")
Prefix = Request("Prefix")
Suffix = Request("Suffix")

Phone = CountryCode & AreaCode & Prefix & Suffix

if Not Regex.IsMatch(Phone,"[0-9]{2}[0-9]{4}[0-9]{4}[0-9]
{3}",RegexOptions.IgnoreCase) then
....

Interesting... and I assume this would go within the button_onclick, but
before the Is_Valid?

If so, this would be a great help. Thanks!! I was just curious, though,
how would I attach a warning message to the message area? I am not
looking to make the fourth validation (the all-fields-or-nothing) cause
the send mail process fail, I just want to throw a warning that if they
proceed, the phone number will not be processed.

Cheers!
...Geshel
--
***********************************************************************
My return e-mail address is an automatically monitored spam honeypot.
Do not send e-mail there unless you wish to be reported as a spammer.
Please send all e-mail to my first name at my last name dot org, with
a subject-line of “NEWSGROUP REPLY FOR NEO GESHEL†(alluppercase).
***********************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top