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
Rick Wright [ Mi, 16 April 2008 10:02 ] [ ID #1943838 ]

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.
Captain Paralytic [ Mi, 16 April 2008 11:12 ] [ ID #1943839 ]

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;
}
}
?>
Larry Anderson [ Mi, 16 April 2008 15:47 ] [ ID #1943840 ]

Re: Validating a field for correct input

Post removed (X-No-Archive: yes)
Notifier Deamon [ Mi, 16 April 2008 20:11 ] [ ID #1943841 ]
PHP » alt.php.sql » Validating a field for correct input

Vorheriges Thema: how to make a link only if exists
Nächstes Thema: Validating fiels for correct input