Reputation: 273
I am looking for a regular expression in JAVASCRIPT to allow a string which satisfies all the three below:
How can I get the regex for both of the above...
I have written regex as ^[0-9a-zA-Z' ']+$
, but this is allowing non ASCII.
I see online that \x00-\x7F
allows non-ASCII chars, but how to combine both of these as a single regex?
Upvotes: 0
Views: 1121
Reputation: 785196
This should work:
var match = str.match(/^(?:(?![^\x00-\x7F"]).)+$/);
Negative lookahead is used to to make sure each character is not non-ASCII OR "
.
OR
var match = str.match(/^(?:(?!")[\x00-\x7F])+$/);
Negative lookahead is used to to make sure each ASCII character is not "
.
Upvotes: 2