Shoaib Iqbal
Shoaib Iqbal

Reputation: 2730

Allow only numbers not starting with zero

I want to allow only numbers which do not start with zero.

I have used the regex ^((?!(0))[0-9]+)$ which worked fine when I tested it with https://www.regextester.com/1926 but in my react app its not working fine.

Can anybody tell me what I am doing wrong here?

EDIT

Here is my code

const sharenumberRegex = /^((?!(0))[0-9]+)$/;
estimatedShareValue: Yup.string()
    .matches(sharenumberRegex, "Invalid number")
    .required('*Please type positive number'),

Upvotes: 0

Views: 938

Answers (1)

Mohammad Faisal
Mohammad Faisal

Reputation: 2392

You can use

 /^[1-9]\d*$/

RegExp Reference

Upvotes: 1

Related Questions