Bose_geek
Bose_geek

Reputation: 498

regular expression for numeric and special chacter check

This is the code I have:-

   var exp = /[^0-9]/g;
    if (!exp.test(char)) {
        args.set_cancel(true);

I want to include special character check meaning I do not want special character to be entered (except backslash).

Upvotes: 0

Views: 150

Answers (1)

anubhava
anubhava

Reputation: 785156

I do not want special character to be entered (except backslash).

You need to define what makes a special character.

Though you can probably use this regex: (as per comments below)

1st case:

var exp1 = /^[a-z]+\\\\[a-z\d]+$/ig;

Demo: http://regex101.com/r/kB1cN5

2nd case:

var exp2 = /^((?!.*?\d)(?!.*?[^\w\s]).)+$/g;

Upvotes: 1

Related Questions