0

I have Regex, it's working as expected in C#, But not working in JavaScript.

if (/\d+(\.\d{0,5})?/.test(data) == false){
    ... //Not going in if 1.23456789
}

C# Code:

[RegularExpression(@"\d+(\.\d{0,5})?", ErrorMessage = "Invalid Value; Maximum 5 places after decimal")]
vivek nuna
  • 16,885
  • 12
  • 74
  • 152
  • 1
    To check if the string fully matches a regex, use anchors, `^` and `$`. `if (/^\d+(\.\d{0,5})?$/.test(data) == false){`. `RegularExpressionAttribute` [requires a full string match](https://stackoverflow.com/a/30483450/3832970) by default. – Wiktor Stribiżew Aug 16 '21 at 12:04

0 Answers0