I have form and form text field which generates dynamically using JSP. And I\'m using Jquery validation but want to add functionlaty to prevent duplicate entry in the form.<
Define a function that returns a boolean after making assertion on the validity of the value:
const isValidGuid = (value) => {
const validGuid = /^({|()?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}(}|))?$/;
const emptyGuid = /^({|()?0{8}-(0{4}-){3}0{12}(}|))?$/;
return validGuid.test(value) && !emptyGuid.test(value);
};
Use $.validator.addMethod
to enable running of the function upon adding the same class name to an element
$.validator.addMethod("isValidGuid", (value) => isValidGuid(value), "Please select a valid and non empty Guid value.");
Use the class name on your desired element: