Last active
August 29, 2015 13:57
-
-
Save vgrem/9545252 to your computer and use it in GitHub Desktop.
PreSaveAction function with Email validation
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
function validateEmail(email) { | |
var re = /^(([^<>()[\]\\.,;:\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,}))$/; | |
return re.test(email); | |
} | |
function PreSaveAction(){ | |
var emailBox = getFieldControl('Email','Text'); | |
if (!validateEmail(emailBox.val())) { | |
var errorHtml = '<span class="ms-formvalidation"><span role="alert">Invalid email address<br></span></span>'; | |
emailBox.after(errorHtml); | |
return false; | |
} | |
return true; | |
} | |
function getFieldControl(fieldName,fieldType) | |
{ | |
var control = $('[id^=' + fieldName + '_][id$=' + fieldType + 'Field]'); | |
return control; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment