Skip to content

Instantly share code, notes, and snippets.

@sudikrt
Created August 8, 2019 17:38
Show Gist options
  • Save sudikrt/2dc597eb74d5adb2879ac4df3b4ac68b to your computer and use it in GitHub Desktop.
Save sudikrt/2dc597eb74d5adb2879ac4df3b4ac68b to your computer and use it in GitHub Desktop.
validateEmail : function(component, event, helper) {
var id = event.getSource().getLocalId();
var emailInp = component.find(id);
var value = emailInp.get("v.value");
var patt = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var res = patt.test(value);
var saveBtn = component.find("saveBtn");
// Is input an email?
if (value != "" && res == false) {
// Set error
emailInp.set("v.errors", [{message:"Invalid Email Address"}]);
saveBtn.set("v.disabled", true);
} else {
// Clear error
emailInp.set("v.errors", null);
saveBtn.set("v.disabled", false);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment