conte Posted July 3, 2006 Posted July 3, 2006 hi, another question to input fields, which i could not find answered in the forums: how could i best validate that in the phone and fax fields only + and numbers are allowed. Standard OSC allows every character. i have tried some regular expressions and it seems to work in the javascript form_check.js.php file, but not in create_account.php file (e.g when javascript is turned off in the browser) here is my code for the create_account.php: //check phone agains regex if ($telephone != '' && strlen($telephone) < ENTRY_TELEPHONE_MIN_LENGTH ) { $error = true; $messageStack->add('create_account', ENTRY_TELEPHONE_NUMBER_ERROR); } if ($fax !='' && strlen($fax) < ENTRY_TELEPHONE_MIN_LENGTH ) { $error = true; $messageStack->add('create_account', ENTRY_FAX_NUMBER_ERROR); } if ($telephone != '' && !(ereg('^(\+|00)[1-9]{1,3}(\.|\s|-)?([0-9]{1,5}(\.|\s|-)?){1,3}$',$telephone))) { $error = true; $messageStack->add('create_account', ENTRY_TELEPHONE_FORMAT_ERROR); } if ($fax !='' && !(ereg('^(\+|00)[1-9]{1,3}(\.|\s|-)?([0-9]{1,5}(\.|\s|-)?){1,3}$',$fax))) { $error = true; $messageStack->add('create_account', ENTRY_FAX_FORMAT_ERROR); } I check if the fields are empty (because they are optional on my site). When they are not empty, they must at least be ENTRY_TELEPHONE_MIN_LENGTH long. When they are not empty, they mus be in one of these formats: +21123456789 +31 1234 12345667 +31123 123 +31.1231.123213123 and so on like in the regex. But i always get the ENTRY_TELEPHONE_FORMAT_ERROR message, no matter how i put in the phone number. Can anyone help please? Or has anyone a better solution for this problem? Thanks
Recommended Posts
Archived
This topic is now archived and is closed to further replies.