Connecting Tech Pros Worldwide Forums | Help | Site Map

Input Box with Masking

ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#1: Jul 15 '09
How can you do input mask inside PHP let say I wanted to input a phone number with this format below:

(123) 4756-7890

dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#2: Jul 16 '09

re: Input Box with Masking


There's no mask. What do you mean by input mask?

A phone number is typically a string of numbers. It should be stripped from all other characters when PHP deals with it (ie put in database), only when presented, the presentation programmer should put the number back in the format desired.

Expand|Select|Wrap|Line Numbers
  1.  
  2. $cleanPhone = preg_replace("/[^0-9]/","",$_POST['phone']); 
  3.  
  4.  
Thanks,



Dan
ddtpmyra's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: CA
Posts: 222
#3: Jul 16 '09

re: Input Box with Masking


Hi Dan,

This is for inputing not saving the numbers on the database. Usually users are confused if they need to put dashes and parenthesis on the form.. But to make it uniform I wanted to put this masking on the text box. How can I do this?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#4: Jul 16 '09

re: Input Box with Masking


Quote:

Originally Posted by ddtpmyra View Post

I wanted to put this masking on the text box. How can I do this?

since PHP is executed on the server it cannot interact with the user's input. you can use a default value for the input field as "mask" together with some styling. or even a background image seems possible. further enhancements can be applied through Javascript.
Reply