background: The project needs to do a two-bit decimal point of the positive and negative floating-point number processing,
Requirements: non-numeric or. Characters are automatically cleared, and the. 12 is automatically patched. Previous 0
principle: Add two events to the input box, KeyUp and Blur,keyup to handle the characters that are not required in the string, and blur the final string into an ideal format 111.11
implementation: Seven regular processing of the main function Val represents the input string
/^\d*\.? \d{0,2}$/Verify that Val is in the DDD.DD format and is not processed.
/[^.0-9]+/to dispose of all the non-numeric and. Characters in Val.
/(?:\ d*\.\d{0,2}|\d+)/converts Val into the correct format.
/^\d+$/when an integer is processed
/^\.\d{0,2}$/with no digits before the decimal point
/^\d+\.\d{0,2}$/the number of digits after the decimal point is processed between 0-2
/^0+[1-9]\d*\.? \d{0,2}$/Val has a 0-time deal ahead of it.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.