Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- checkIfInteger(string) {
- let errors = 0;
- string.split("").forEach(digit => {
- if (isNaN(digit)) errors++;
- });
- if (!errors) return true;
- }
- checkIfNumber(string) {
- let errors = 0;
- if (string.split('.').length === 2) {
- (string.split('.')[0]).split('').forEach(digit => {
- if (isNaN(digit)) errors++;
- });
- (string.split('.')[1]).split('').forEach(digit => {
- if (isNaN(digit)) errors++;
- });
- if (string.split('.')[1].length > 2 || string.split('.')[1].length < 1) errors++;
- } else {
- string.split("").forEach(digit => {
- if (isNaN(digit)) errors++;
- });
- }
- if (!errors) return true;
- }
Add Comment
Please, Sign In to add comment