Guest User

Untitled

a guest
Nov 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Decimal Validator</title>
  6. <script>
  7.  
  8. function validateDecimal(valor) {
  9.  
  10. var regex = /^\d+(?:\.\d{0,2})$/;
  11. if (regex.test(valor)) {
  12. return true;
  13. } else {
  14. return false;
  15. }
  16. }
  17.  
  18. console.log("2 -> "+validateDecimal(2));
  19. console.log("2.54 -> "+validateDecimal(2.54));
  20. console.log("2.5454 -> "+validateDecimal(2.5454));
  21. </script>
  22. </head>
  23. <body>
  24.  
  25. </body>
  26. </html>
Add Comment
Please, Sign In to add comment