473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Validate multiple form fields with one method

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).
************************************************** *******************
Feb 26 '07 #1
2 2376
On Feb 26, 9:27 am, Neo Geshel <got...@geshel.orgwrote:
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
.....

Feb 26 '07 #2
Alexey Smirnov wrote:
On Feb 26, 9:27 am, Neo Geshel <got...@geshel.orgwrote:
>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).
************************************************** *********************
Feb 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
5
by: Red | last post by:
Hi, I'm not very familiar with Javascript. I usually leave that kind of stuff up to Dreamweaver, but i'm starting to need a little more than it can offer. I have an asp page which creates a...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
11
by: wolf | last post by:
There are three webcontrol on my asp.net form: a TextBox, a submit button and a RegularExpressionValidator. And I had set ControlToValidate property of the RegularExpressionValidator to the...
3
by: Martin | last post by:
Hi, I am implemeting a form in asp.net. The form is quite large and the validation is reasonably complex, so I have decieded to implement my own validation rather than use any custon...
12
by: shank | last post by:
I'm trying to use online samples for submitting multiple records from ASP into a stored procedure. Failing! Through the below form, a user could be submitting many records at a time. I'm not...
11
by: TokyoJ | last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)? I'm using the RegExp function...
5
by: phpCodeHead | last post by:
I am needing to determine how to go about validating that a field in my form contains only a positive integer. I know that this is fairly simple if the form contains only one element to be...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.