Issue
How to restrict multiple negative sign in the textbox. below code is not allowing my to type even single negative symbol.
my regex code -
public AmountFormat ="^(\\+?\\-? *[0-9]+)([,0-9]*)([0-9])*$";
error -
not allowing to enter (-) symbol if i write regex in the variable.
public AmountFormat ="((^|, )(-|-?[0-9]\d*(\.\d+)?))+$"; //not working
return /((^|, )(-|-?[0-9]\d*(\.\d+)?))+$/.test(input);//working
Solution
try
public AmountFormat =/^-?\d*(\d\.\d*)?$/;
details:
const isValid = (input) => {
const AmountFormat = /^-?\d*(\d\.\d*)?$/;
return AmountFormat.test(input);
}
console.warn(isValid('100'));
// true
console.warn(isValid('-100.0'));
// true
console.warn(isValid('--100'));
// false
console.warn(isValid('-'));
// true
Answered By - Jafar Jabr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.