Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:19:52+00:00 2026-06-09T10:19:52+00:00

I am trying and failing hard in validating a phone number within jQuery validation.

  • 0

I am trying and failing hard in validating a phone number within jQuery validation. All I want is to allow a number like (01660) 888999. Looking around the net I find a million examples but nothing seems to work. Here is my current effort

$.validator.addMethod("phonenumber", function(value) {
  var re = new RegExp("/[\d\s()+-]/g");
  return re.test(value);
  //return value.match("/[\d\s]*$");
}, "Please enter a valid phone number");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:19:53+00:00Added an answer on June 9, 2026 at 10:19 am

    Bergi is correct that the way you are constructing the regular expression is wrong.

    Another problem is that you are missing anchors and a +:

    var re = /^[\d\s()+-]+$/;
    

    Note though that a regular expression based solution will still allow some inputs that aren’t valid phone numbers. You can improve your regular expression in many ways, for example you might want to require that there are at least x digits, for example.

    There are many rules for what phone numbers are valid and invalid. It is unlikely you could encode all those rules into a regular expression in a maintainable way, so you could try one of these approaches:

    • Find a library that is able to validate phone numbers (but possibly not regular expression based).
    • If you need a regular expression, aim for something that is a close approximation to the rules, but doesn’t attempt to handle all the special cases. I would suggest trying to write an expression that accepts all valid phone numbers, but doesn’t necessarily reject all invalid phone numbers.

    You may also want to consider writing test cases for your solution. The tests will also double as a form of documentation of which inputs you wish to accept and reject.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play with jQuery mouseenter and mouseleave events but failing. Here
I’m trying to create a date in the BC era, but failing pretty hard.
I'm trying to get a setup running with all these and I'm failing so
I'm trying to get a count of passing and failing devices I have all
I am desperately trying and failing to hook CallWndProc using EasyHook. Intptr addr =
I'm trying (and failing) to write a simple template file: <#@ template language=C# hostspecific=True
I am trying and failing to add datepicker to inputs that are created dynamically.
After trying to make a while(bool) loop and it failing because I couldn't see
i am really trying to do this but i am failing to find a
I'm trying to retrieve hierarchical data from a table but am failing to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.