- Posts: 261
- Thank you received: 32
Validation for Phone Number Field
- Danielle Kinney
- Topic Author
I understand there is some validation already set in the Phone Number field. However, I was wondering if it would be possible to enhance the Phone Number field validation. One of my clients is receiving incomplete phone numbers and words in the field in an effort to circumvent completing this required field.
The Goal: Only allow numeric characters in the Phone Number field; regardless of "optional" or "required"
1. Add a pull down menu in the Phone Number field, which allows the Joomla admin to set a min. number of numeric characters required in the form. I think having this as an option would address each country's phone number digit requirements.
Example: in the US our Phone Number format is:
(3 digit numeric area code) "hyphen" 3 digit numeric "hyphen" 4 digit numeric
2. To reduce confusion in the FC user community and to accomodate other countries. Default the module setting to "N/A" to work with the users who do not desire this feature. Thus the validation will only look to "optional" or "required". It will not validate to the items I listed above.
3. Only allow numeric characters in the phone number field for every type of form regardless if they wants to change the N/A in the pull down menu
4. Add the fox error message when a user does not comply with the numeric requirement or length of the field requirement. I know when a user adds a "." it produces a fox error message but it doesn't produce an error when the user enters text such as "no way" or "will not provide"
5. Validation Suggestions:
a) If the admin sets the phone number field to "required" and did not change the "N/A" pull down menu, then the validation will check for only numeric and ignores the digit requirements
b) If the admin sets the phone number field to "required" and selected "10" from the pull down menu, then the validation will check for only numeric and the "10" digit requirements as listed in the pull down menu
c) The same approach can be used for the "Optional". This says if the user chooses to add their phone number they still have the option to comply with the total number of digits required
6. Create a uniuqe area code field which sits left of the main phone number. This may be too US specific and not best for the entire FC user community. Today, I work around this by creating a field to the left of the phone number field and set it to inline. It is a challege and time consuming but it does work.
It would be wonderful if we could also make similar changes to the Name Fields, City, State fields as well. In the US there are only Alpha characters for the City, State.
US state abreviations are 2 alpha characters only and one day I would love to create this as a pre populated pull down menu. (this is a different enhancement request)
US zip codes are numeric characters only
As for the hypens in the phone number I am not sure that should be hard coded since some folks may want to import the email message into a contact data base. Not sure. But might be worth thinking about.
- Posts: 6
- Thank you received: 0
Validation is an absolute must have.
- Graeme Moffat
- Posts: 724
- Thank you received: 99
HTML5 has this regex validation model built in, but since the page type is set by the template, extension developers cannot rely on that (yet).
Google has a "libphonenumber" library but even that needs to know the country, at least (I haven't looked closely at it).
I notice that there are now two internationally used number formats, ITU-T E.123 and EPP.
One possibility could be to provide a limited number of regex's for the admin to choose from, with a corresponding example of what is accepted, which would also be shown on the form itself.
Or perhaps a compromise would be to widen dkinney's specs slightly; allow a leading "+" (for international numbers), digits, spaces (compress to 1?), and hyphens, with a trailing digit.
Remember that FC does not do anything with these numbers, merely passes the whole field on as a string for the (human) email receiver to deal with.
While reading some forums on this topic, I came across the following, which I think is food for thought -
If the user wants to give you his phone number, then trust him to get it right. If he does not want to give it to you then forcing him to enter a valid number will either send him to a competitor's site or make him enter a random string that fits your regex. I might even be tempted to look up the number of a premium rate sex line and enter that instead.
If the user doesn't want to enter his phone number you can just allow the field to be optional, but is it too much to ask the user to enter a valid phone number if they are going to enter one?
Also a role of validation is simply to remind people to add area codes etc that they might not otherwise remember to add
Of course, in the end, as web site developers we have to do what the client requires!
- Posts: 1
- Thank you received: 0
But since it's kind of limited i switched into using Veriphone