close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Validate to accept UK phone numbers only

Thread began 3/14/2016 11:52 am by s.joiner74419001 | Last modified 2/28/2018 1:09 pm by Ray Borduin | 332 views | 10 replies |

s.joiner74419001

Validate to accept UK phone numbers only

I am wanting to validate a form field to accept UK phone numbers only and I assume I need to use regular expressions to achieve this but I am alien to using regular expressions. Subsequently I found websites with examples to use. I have tried the following:

"/^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/"

But it doesn't seem to work.
It supposedly should accept the following.

07222 555555
(07222) 555555
+44 7222 555 555

Any ideas as to where I am going wrong?
I've attached the page if it helps.

Thanks in advance.

Attached Files
application_e.php
Sign in to reply to this post

Ray BorduinWebAssist

You don't need the open and close pattern indicators... the pattern should just be:

(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}

Sign in to reply to this post

Justin@AdventDesign

Accept UK and US numbers

Hi Ray - this should be a quick one... my client wants to add support for UK phone number validation in addition to US numbers. Currently the validation pattern reads "\(\d{3}\) \d{3}[\-]\d{4}". I'm assuming I can modify it with the UK pattern in this thread, however I'm unsure how to do an either/or scenario so that both of these patterns will be acceptable.

Sign in to reply to this post

Ray BorduinWebAssist

I think you should be able to just separate them with an "|" symbol.

Something like:

"(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}|\(\d{3}\) \d{3}[\-]\d{4}"

You would probably have to remove the formatting options if it is auto-formatting to add parenthesis as well.

Sign in to reply to this post

Justin@AdventDesign

It appears to be doing the auto formatting to add parenthesis. How do I turn off auto formatting?

Odd thing I noticed too when poking around. The Server Validation for Phone Number was set to "Allow international", yet it wouldn't accept anything other than US 3+3+4 numbered format.

Sign in to reply to this post

Ray BorduinWebAssist

Remove the onblur code in the html input field. The client validation was forcing US format even though the server validation would have allowed international if it got there.

Sign in to reply to this post

Justin@AdventDesign

Thanks Ray! I think we've got it nailed down.

Sign in to reply to this post

Justin@AdventDesign

Sorry to ping you on this one again Ray but I've tried this six ways to Sunday and still have yet to get the validation to work. I'm about ready to just drop the validation and make it a simple required field, but it would be nice to at least confirm that it is plausibly a valid phone number.

I've pulled the 'onblur' as suggested, and tried both leaving the WA validation as a phone number, as well as switching it to a regular expression using the combined regular expression you suggested. The validation gets flagged regardless of what I try.

I think part of my frustration here, as with many of these issues I run into, is I don't know how to get sufficient troubleshooting information. I'm guessing there's a way to actually print some detailed information on the validation error, but I haven't found a way to do it.

PM'ing you with the page and link in case you have any other suggestions.

Sign in to reply to this post

Ray BorduinWebAssist

The syntax for regular expressions on client and server are a little different. In the server field I think you need to encapsulate it with slashes like:
/(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}|\(?\d{3}\)?\s?\d{3}[\-]?\d{4}/

I'd use the original phone validation for the server. Your client validation is working, but it is very specific and without the auto-formatting it might be difficult for people to enter the correct value.

For instance if they enter a US phone number they would need to type: (222) 333-4444

If any spaces, dashes or parenthesis are missing it wouldn't pass.

A better regular expression might be:
(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}|\(?\d{3}\)?\s?\d{3}[\-]?\d{4}

That would at least allow them to omit the parenthesis, dash, and space

Sign in to reply to this post

Justin@AdventDesign

I'm unclear as to which part is server vs client validation. Is the stuff on line 25 the server, and the the code within the HTML tag for client validation?

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...