Solved

JavaScript Regex validation - simple list of allowed chars

Posted on 2011-09-26
3
152 Views
Last Modified: 2012-05-12
Hi.  

Please can someone show me the correct regex for ensuring input has ONLY the following list of chars, in any order:

0123456789-+()

Any number of whitespace is allowed.

My test code attached.

TIA, TheFoot


function(v_val){
	return /^[0-9-+]$/.test(v_val);
}

Open in new window

0
Comment
Question by:Barry Jones
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36599741
function(v_val){
	return !/[^\d-+()]/.test(v_val);
}

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36599749
if you want to allow whitespace :

function(v_val){
	return !/[^\d\s-+()]/.test(v_val);
}

Open in new window

0
 
LVL 12

Author Closing Comment

by:Barry Jones
ID: 36600224
Awesome!  Thanks for your quick response..
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question