Created
March 29, 2022 09:04
-
-
Save pujie/e765e8db42e9a5da4da71d1f9e2e951d to your computer and use it in GitHub Desktop.
validate multiple elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isEmail = element => { | |
arr1 = element.split('@') | |
if(arr1.length === 0){ | |
return false | |
}else if(arr1[0].trim() === ""){ | |
return false | |
}else if(arr1[1].trim() === ""){ | |
return false | |
}else{ | |
return true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isNotEmpty = element => { | |
if(element.trim() === ""){ | |
console.log("Its empty bro",element.trim()) | |
return false | |
}else{ | |
console.log("Its not empty bro",element.trim()) | |
return true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<input type="text" id="input1" /> | |
<input type="text" id="input2" /> | |
<input type="text" id="testemail" /> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let v = validation | |
let isvalid = v | |
.inspectElement({valid:isNotEmpty($("#input1").val())}) | |
.inspectElement({valid:isNotEmpty($("#input2").val())}) | |
.inspectElement({valid:isEmail($("#testemail").val())}) | |
.getValid()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validation = { | |
doCheck : (obj,callback) => { | |
callback(obj.par1 && obj.par2) | |
return validation | |
}, | |
inspectElement : element => { | |
return validation.doCheck({ | |
par1 : element.valid, | |
par2 : validation.valid | |
},res => { | |
validation.valid = res | |
}) | |
}, | |
getValid : _ => { | |
return validation.valid | |
}, | |
valid:true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple validation of multiple elements by javascript