|
![Picture of mrbinky 3000 Picture of mrbinky 3000](/graphics/unknown.gif) mrbinky 3000 - 2007-09-26 03:57:01
I am trying to validate a fax number. The fax number is optional. The field can be blank OR it can be a valid 10 digit phone number. I tried using the regular expression option.
$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"fax",
"ID"=>"fax",
"MAXLENGTH"=>12,
"LABEL"=>"<u>F</u>ax",
"ACCESSKEY"=>"F",
"TABINDEX"=>$ti++,
"ValidateRegularExpression"=>array(
'^$',
'[0-9]{3}-[0-9]{3}-[0-9]{4}'),
"ValidateRegularExpressionErrorMessage"=>array(
'',
"Please use a 10 digit fax number seperated by dashes.")
));
How can I make something valid if is blank OR matches the regular expression.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-09-26 05:12:27 - In reply to message 1 from mrbinky 3000
I am not sure if regular expressions can match empty values. Anyway, you can always use the ValidateOptionalValue parameter set to an empty string to make the validation accept empty strings without further validation.
![Picture of mrbinky 3000 Picture of mrbinky 3000](/graphics/unknown.gif) mrbinky 3000 - 2007-09-26 06:27:44 - In reply to message 2 from Manuel Lemos
Thanks. I set ValidateOptionalValue to '' and the field now accepts blank values OR valid 10 digit fax numbers. Here is the code for those interested
$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"fax",
"ID"=>"fax",
"MAXLENGTH"=>12,
"LABEL"=>"<u>F</u>ax",
"ACCESSKEY"=>"F",
"TABINDEX"=>$ti++,
"ValidateOptionalValue"=>'',
"ValidateRegularExpression"=>array('[0-9]{3}-[0-9]{3}-[0-9]{4}'),
"ValidateRegularExpressionErrorMessage"=>array("Please use a 10 digit fax number separated by dashes."),
));
|