Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Decimal Validator</title>
- <script>
- function validateDecimal(valor) {
- var regex = /^\d+(?:\.\d{0,2})$/;
- if (regex.test(valor)) {
- return true;
- } else {
- return false;
- }
- }
- console.log("2 -> "+validateDecimal(2));
- console.log("2.54 -> "+validateDecimal(2.54));
- console.log("2.5454 -> "+validateDecimal(2.5454));
- </script>
- </head>
- <body>
- </body>
- </html>
Add Comment
Please, Sign In to add comment