Link to home
Start Free TrialLog in
Avatar of Barry Jones
Barry JonesFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of leakim971
leakim971
Flag of Guadeloupe image

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Barry Jones

ASKER

Awesome!  Thanks for your quick response..