Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

JavaScript Regex validation - simple list of allowed chars

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
Barry Jones
Asked:
Barry Jones
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
function(v_val){
	return !/[^\d-+()]/.test(v_val);
}

Open in new window

0
 
leakim971PluritechnicianCommented:
if you want to allow whitespace :

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

Open in new window

0
 
Barry JonesAuthor Commented:
Awesome!  Thanks for your quick response..
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now