From fields - Can I mandate a format for phone and SS# ?

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Post Reply
earcandy
Forum Members
Forum Members
Posts: 58
Joined: Sat Jan 11, 2014 4:37 pm

From fields - Can I mandate a format for phone and SS# ?

Post by earcandy »

Is it possible in my html form to require that phone numbers be entered as ###-###-#### and SS#'s as ###-##-#### ?

I am fairly new to this and figured out how to use required and placeholder but neither demands the user enter these two fields in these formats.

Appreciate any help.

Code: Select all

Home Ph:<strong> <input name="HomePhone" type="text" placeholder="XXX-XXX-XXXX" required/>

Social Security Number:&nbsp;&nbsp;
	<input name="SocialSecurity" type="text" placeholder="XXX-XX-XXXX" />
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: From fields - Can I mandate a format for phone and SS# ?

Post by JohnnyB »

The best way to do it is using Javascript.
There is a jQuery plugin called "maskit" that I've used successfully in the past. There are other similar ones too.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: From fields - Can I mandate a format for phone and SS# ?

Post by velden »

I think you should also consider doing some SERVER side validation if you want to be sure valid information is entered.

jQuery is client side scripting. Client (side) input should never be trusted. Maybe it's not that important in this case.

If you're using Form Builder for this form: it has possibility to do some regex checks on submitted fields.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: From fields - Can I mandate a format for phone and SS# ?

Post by paulbaker »

Remember, too, that depending on your application you need to consider phone number formats worldwide - the format you give would be no good for UK numbers, for example.
Post Reply

Return to “Layout and Design (CSS & HTML)”