jquery - javascript regex for score -


Reggae for this type of marks are for students: 12.5, 99.5, 87, 1.66

  • Fields may be empty
  • The maximum character length (.) Is 5 as follows: 99.99

  • between digits 0 and 100

I used it, but it does not work

  var rmark = / ^ \ d {0,1} \. (\ D {0,4}) $ /; Var txtS = $ (": text"); (Var i = 0; i  

  / ^ \ d { 1,2} (\. \ D {1,2})? $ /  

And this means ...

  ^ - String \ d {1,2} from the beginning - 1 or 2 digits (- Capture Group which is not required - survived dot \ d {1,2} - 1 or 2 digits)? - String  

ps: If it is empty then / ^ (\ d {1,2} (at the end of the string) - this group is not required to be present \ . \ D {1,2})?)? $ /

pps: If the range from 0 to 100 then / ^ (100 | (\ d {1,2}} (\. \ D {1,2 })? $ $ /

Or you can test it here - play snippet

  $ (function () {$ ('Input'). Key (function () {var regexp = / ^ (100 ((\\\\\\\\\\\\\\\\\\\\ {1 , $ 2;)?)? $ /; If (! Regexp.test ($ (this) .val ()) $ (this). AddClass ('bad'); and $ (this) .removeClass ('bad' );}};});  
  .bad {color: red;}  < / Pre> 
  & lt; script src =" https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery .min.js "& gt; & lt; / script & Gt; & lt; input type = "text" & gt;  


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

class - Kivy: how to instantiate a dynamic classes in python -

python - mayavi mapping a discrete colorbar on a surface -