Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Validating a field for correct input

 
   Database Help (Home) -> PHP SQL RSS
Next:  Validating fiels for correct input  
Author Message
Rick Wright

External


Since: Apr 16, 2008
Posts: 2



(Msg. 1) Posted: Wed Apr 16, 2008 1:02 am
Post subject: Validating a field for correct input
Archived from groups: alt>php>sql (more info?)

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

 >> Stay informed about: Validating a field for correct input 
Back to top
Login to vote
Captain Paralytic

External


Since: Jan 14, 2008
Posts: 200



(Msg. 2) Posted: Wed Apr 16, 2008 2:12 am
Post subject: Re: Validating a field for correct input [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 16 Apr, 08:02, "Rick Wright" <rbw95... DeleteThis @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.

 >> Stay informed about: Validating a field for correct input 
Back to top
Login to vote
larry

External


Since: Dec 14, 2007
Posts: 75



(Msg. 3) Posted: Wed Apr 16, 2008 6:47 am
Post subject: Re: Validating a field for correct input [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Apr 16, 1:02 am, "Rick Wright" <rbw95... DeleteThis @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;
}
}
?>
 >> Stay informed about: Validating a field for correct input 
Back to top
Login to vote
Tom

External


Since: Oct 15, 2007
Posts: 42



(Msg. 4) Posted: Wed Apr 16, 2008 11:11 am
Post subject: Re: Validating a field for correct input [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> PHP SQL All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]