Converting C# regular expression to JavaScript regular expression -


I have created a regular expression in C # that I am using in model recognition. I have the same requirements in javascript Please help me convert.

There is a regular expression in C #

  [required] [display (name = "cost")] [datatype (query)] [regular expression (@ "^ (([A-zA-Z] + | | (\ d {0,15}. \ D {0,2})) $", error message = "cost can not be more than 2 decimal places ") [Range (type)," 0.01 "," 99999999999999.99 ", errormess =" {0} must be greater than one decimal / number 0 and less than 100 billion billion. ")] Public taps qualified & lt; Decimal & gt; Cost {Received; Set; }   

and another verification message should be "Number one field"

I'm trying in JavaScript like this var regExp = new RegExp ("(([a-zA-Z] +) | (\ d {0,15}. \ D {0,2})));); var res = RegExp.test ($ ('# cost'). Val ());

But it always gives the truth

thanks

If you are trying to verify that the cost must be 2 decimal places, then "or" part in your regex To any alpha string Account:

  ^ (\ d {0,15} \. \ D {0,2}) $   

Note: You can enter parenthesis There is no need to be because you are not going to do anything with the value captured here

The regex that you mentioned will also fail in C #, but you can change your range

And in the end, if you are using New Regexp syntax, you need to avoid slash:

  var re = new RegExp ("^ \ \ D {0,15} \\. \\ d {0,2} $ "); // or small JS syntax var re = / ^ \ d {0,15}.   

The sample runs:

  console.log (re.test ("abc"); // false console.log (re.test ("10.23"); // true console.log (re.test ("10 ")); // false    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

c++ - Qt::make_shared for creating QSharedPtr as std::make_shared for creating std::shared_ptr -