Skip to content

Instantly share code, notes, and snippets.

@sungraizfaryad
Last active August 17, 2019 17:26
Show Gist options
  • Select an option

  • Save sungraizfaryad/6850b4947b15b15edbd93969726d7a9d to your computer and use it in GitHub Desktop.

Select an option

Save sungraizfaryad/6850b4947b15b15edbd93969726d7a9d to your computer and use it in GitHub Desktop.
You can use these methods to block any email extension and it can also prevent users to add URL in textarea field.
// Block ru extention in email like www.google.ru
$.validator.addMethod("noRu", function(value, element) {
return (this.optional(element) || value.slice(-3) != ".ru");
}, "The .ru extention is not allowed in email address");
// Prevent users to add any URL in textarea
$.validator.addMethod("noUrl", function(value, element) {
return (this.optional(element) || value.match(/\b(http|https)?(:\/\/)?(\S*)\.(\w{2,4})(.*)/g) == null);
}, "URL is not allowed");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment