Validating a field for correct input
GlacierHi -
I need to validate a field in my database where the user will input their
phone number. I would like to ensure that the area code is included. The
field is setup as follows:
hphone varchar(12)
What is the best way to check to see if this format 123-456-7890 is entered?
Thank you in advance for any assistance.
- Rick
Re: Validating a field for correct input
On 16 Apr, 08:02, "Rick Wright" <rbw95... [at] gmail.com> wrote:
> GlacierHi -
>
> I need to validate a field in my database where the user will input their
> phone number. I would like to ensure that the area code is included. The
> field is setup as follows:
>
> hphone varchar(12)
>
> What is the best way to check to see if this format 123-456-7890 is entered?
> Thank you in advance for any assistance.
>
> - Rick
How will the user get their data into the table? Since you are posting
in alt.php.sql, I assume it is through some sort of php driven web
form.
So use a REGEX in either javascript and/or php to verify the format
before loading it into the table.
Re: Validating a field for correct input
On Apr 16, 1:02 am, "Rick Wright" <rbw95... [at] gmail.com> wrote:
> GlacierHi -
>
> I need to validate a field in my database where the user will input their
> phone number. I would like to ensure that the area code is included. The
> field is setup as follows:
>
> hphone varchar(12)
>
> What is the best way to check to see if this format 123-456-7890 is entered?
> Thank you in advance for any assistance.
>
> - Rick
Here ya go. I had to look for one a while back.
<?php
function checkPhone($number){
if(ereg("^[0-9]{3}-[0-9]{3}-[0-9]{4}", $number)) {
return true;
} else {
return false;
}
}
?>
Re: Validating a field for correct input
Post removed (X-No-Archive: yes)