Validating a field for correct input
am 16.04.2008 10:02:45 von Rick Wright
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
am 16.04.2008 11:12:59 von Captain Paralytic
On 16 Apr, 08:02, "Rick Wright" 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
am 16.04.2008 15:47:23 von Larry Anderson
On Apr 16, 1:02 am, "Rick Wright" 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.
function checkPhone($number){
if(ereg("^[0-9]{3}-[0-9]{3}-[0-9]{4}", $number)) {
return true;
} else {
return false;
}
}
?>