Jump to content

Recommended Posts

Yep, you can use javascript and check for number of characters inputed every time the field changes or a key is pushed, and then add space or '-' or ':' as the next delimiter in the field.

 

With a little hassle you can also have a default '__ __ __ __' or something in your field, and update how it looks after each time they enter something.

 

But, no, there is no easy or built-in way to do it.

Link to comment
https://forums.phpfreaks.com/topic/36685-solved-masking-fields/#findComment-175056
Share on other sites

I've always used the password type to mask fields, since I do not think writing a custom way would be worth the time/effort at all.  Maybe he means something else by masking, but if he means hiding the content by replacing the characters with something else that would mean nothing to someone that didn't type it, then asterisks via the password fieldtype are perfect.  Also, JS is not enabled by some (very few) users so he could still use the password field type and then use your method so it wouldn't use asterisks if the user has JS, but if they didn't it would, thus still hiding the content.

 

Or I could be entirely wrong and he is trying to make a field that is default "---------" and then you enter 1 and it becomes "1--------".  Then another number: "14-------" so on... If that's the desired effect then that could easily be accomplished by javascript, but remember to set the value via JS also, so that a user with out JS will not have to manually delete what is in there... That oddly confuses some people... lol

Link to comment
https://forums.phpfreaks.com/topic/36685-solved-masking-fields/#findComment-175077
Share on other sites

oooook.  To be clear I am not looking to hide the input like you would do for a password. By masking I mean to format, to make the input appear in a specific way. Like a phone number to look like the standard (555)555-5555 or a SSN to appear as XXX-XX-XXXX.  Whatever term you use for this is what I am trying to get direction on. Sorry for the confusion.

Link to comment
https://forums.phpfreaks.com/topic/36685-solved-masking-fields/#findComment-175139
Share on other sites

For phone numbers, I use three boxes.  Then I use JS to auto jump to the next box as the number is filled out.  This way, if they don't have JS, they can still use it the old fashioned way.  :D  Then I take the three fields, put a dash between them and store the properly formatted number in the DB.

Link to comment
https://forums.phpfreaks.com/topic/36685-solved-masking-fields/#findComment-175241
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.