Email Validation...
Is there a javascript function we can use to validate the format of the entry a user makes in a Email field? I know we can do this at SharePoint level but the use case we have requests that the validation is done when user has input the email address not when save is pressed..
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Yes, it's totally possible to implement using JavaScript Editor inside of Forms Designer. For example, you can use code like this to check if email is valid or not:
Replace FieldName with the Internal name of your field first though.
Code: Select all
var $result = fd.field("FieldName").control()._el().find("br");
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 validate() {
fd.field("FieldName").control()._el().find(".ms-formvalidation").remove();
var email = fd.field("FieldName").value();
if (validateEmail(email)) {
return true;
}
$result.after('<span class="ms-formvalidation"> Enter a valid Email address.</span>');
return false;
}
fd.onsubmit(function(){
return validate();
});
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 19 guests