Jump to content

Input Masks


jkkenzie

Recommended Posts

When a user is keying in date on a page input box for date, how do you people out there make sure that date is entered properly using an input mask or javascript or what?

 

How about the input for currency? i.e a user wants to input a price of an item, there has to be a comma after every three characters from the left and a $ sign before the integers, how do you do this ?

 

What are the codes?

 

Regards,

Joseph

Link to comment
https://forums.phpfreaks.com/topic/102352-input-masks/
Share on other sites

You know how to use PHP, right?  Then it's quite simple.  For the number one, just use number_format(), and for the date one, just validate it by making sure the month is less than 12 but > 1, and date is >1 but <31 (depending on month), and make sure the year is between 1970 and 2008.  Or however high you want it to go.

Link to comment
https://forums.phpfreaks.com/topic/102352-input-masks/#findComment-524086
Share on other sites

Indeed. Forcing the user to put their own date separators in isn't great in my opinion. You should use three different text boxes and place the slashes/dashes yourself.

 

As for validation, most people would use javascript and PHP. Javascript is user friendly, since a user will be notified of mistakes without having to submit the page and wait for a reload. However, you need PHP to repeat the checks server side, since a user may have javascript turned off.

Link to comment
https://forums.phpfreaks.com/topic/102352-input-masks/#findComment-524105
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.