javascript - Allow saving of a number that begins with a decimal point -
I've got a jsp form, and some fields take dollar amount:
& Lt; Tr id = "zodiac" style = "visibility: visible;" & Gt; & Lt; Td> & Lt; Numbered & gt; 1) & amp; Nbsp; Lt; / Numbered & gt; Total Compensation: US $ & lt; Html: text maximum length = "11" size = "11" property = "user.compensation" style class = "required compensation currency" /> & Lt; Span class = "mandatory" & gt; & Lt; / Span & gt; & Lt; Br / & gt; & Lt; Span class = "errors" & gt; & Lt; / Span & gt; & Lt; Br / & gt; & Lt; / TD & gt; & Lt; / TR & gt; It uses jquery.validate.js for verification, and it has been requested that we allow ".123" (versus 0.123) Give.
indicates function in JS:
// http://docs.jquery.com/Plugins/Validation/Methods/number Number: function (value, element) ) {Return it Alternative (element) || /^- ?( ?:dd+|\d {1,3}( ?:,d{3})+)( ?:\\\\\\\\\\\\\\\\\\ }, But how can I change this to save the number starting at the decimal point?
This section of your regex:
(?: \ D + | \ D {1,3} (?, \ D {3}) +) matches the digits before decimal point It's more than one or more digits ( \ d {1, 3} (?:, \ D {3}) + part)
So, just make it optional: < / P>
^ -? (?: \ D + | \ {{1,3} (?:, \ D {3}) +)? (?: \. \ D +)? $ ^ | Matches 0 or 1 time Test it, and keep in mind that regex101 is a very useful tool for decoding the rezjects and you should use it.
Comments
Post a Comment