Guest User

Untitled

a guest
Jun 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. checkIfInteger(string) {
  2. let errors = 0;
  3. string.split("").forEach(digit => {
  4. if (isNaN(digit)) errors++;
  5. });
  6. if (!errors) return true;
  7. }
  8. checkIfNumber(string) {
  9. let errors = 0;
  10. if (string.split('.').length === 2) {
  11. (string.split('.')[0]).split('').forEach(digit => {
  12. if (isNaN(digit)) errors++;
  13. });
  14. (string.split('.')[1]).split('').forEach(digit => {
  15. if (isNaN(digit)) errors++;
  16. });
  17. if (string.split('.')[1].length > 2 || string.split('.')[1].length < 1) errors++;
  18. } else {
  19. string.split("").forEach(digit => {
  20. if (isNaN(digit)) errors++;
  21. });
  22. }
  23. if (!errors) return true;
  24. }
Add Comment
Please, Sign In to add comment