Validation for Phone Number Field

20 Nov 2013 15:56 - 20 Nov 2013 15:57 #1 by Danielle Kinney
Validation for Phone Number Field was created by Danielle Kinney

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.

Please Log in or Create an account to join the conversation.

08 Jan 2014 04:34 #2 by Frost
Replied by Frost on topic Validation for Phone Number Field
I need validation as well. However, I'm not sure what validation is already in place for phone number as it's just a plain text input box.

Validation is an absolute must have.

Please Log in or Create an account to join the conversation.

20 Jan 2014 03:28 #3 by Graeme Moffat
Replied by Graeme Moffat on topic Validation for Phone Number Field
dkinney's ideas are good and I'm sure Fox has noted them. But as she infers, there is no generic (one-size-fits-all) solution since there are many different valid formats for different countries. The ideal (in my view) would be for site admins to provide a regular expression template to validate against, but how many admins are capable of doing that? That's not meant as a put-down, a large percentage of admins do not have a programming background (the point of using a CMS like Joomla is to allow a wide spread of abilities to produce web sites) and even then, many programming types are not comfortable (or competent, for that matter) with regex's.
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!

Please Log in or Create an account to join the conversation.

14 Mar 2020 20:03 - 14 Mar 2020 20:03 #4 by aymanrida
Replied by aymanrida on topic Validation for Phone Number Field
I Don't know if it will help you but for my case I was using regex to verify the input of phone number and here's the code:

But since it's kind of limited i switched into using Veriphone

Please Log in or Create an account to join the conversation.

17 Jun 2020 18:15 #5 by Rim El Bakkali
Replied by Rim El Bakkali on topic Validation for Phone Number Field
The phone validation field is already a big industry nowadays, you can have access to different websites with very interesting pricing. I would recommend, it operates in more than 240 countries and has attractive prices.
Prices are as follows: $6.99/month for 5000 verifications, $29/month for 50k verification, $79/month for 250k verification and $199/month for 1 million verification. Or top-up your account with never-expiring pay-as-you-go credits: 10k verification for $19, 25k verification for $39, 50k verification for $59, 100k verification for $89, 250k verification for $169, 500k verification for $259, 1 million verification for $399 and 5 million verification for $999. Moreover, if you have less than 1000 verification, it is for free!

Please Log in or Create an account to join the conversation.