Mahajan344
Mahajan344

Reputation: 2550

Jquery validation on numbers with plus minus optional

I am working on MVC4 project where i have textbox in which i have to enter max 5 numbers but those number could be -ive or +ive

So i am using custom jquery validation but this is not satisfying the requirement here is validation expression i am using

 "onlyNumberSp": {
                    "regex": /^[0-9]+$/,
                    "alertText": "* Numbers only"
                }, 

I know this is not correct expression so how can i achieve this functionality where user can enter max of 5 numbers with - or + or may not enter any sign.

Upvotes: 0

Views: 1320

Answers (1)

NaYaN
NaYaN

Reputation: 1320

"onlyNumberSp": {
    "regex": /^-?\d{1,5}$/,
    "alertText": "* Numbers only"
}, 

Upvotes: 2

Related Questions