emailAddress.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. (function($) {
  2. $.fn.bootstrapValidator.i18n.emailAddress = $.extend($.fn.bootstrapValidator.i18n.emailAddress || {}, {
  3. 'default': 'Please enter a valid email address'
  4. });
  5. $.fn.bootstrapValidator.validators.emailAddress = {
  6. enableByHtml5: function($field) {
  7. return ('email' === $field.attr('type'));
  8. },
  9. /**
  10. * Return true if and only if the input value is a valid email address
  11. *
  12. * @param {BootstrapValidator} validator Validate plugin instance
  13. * @param {jQuery} $field Field element
  14. * @param {Object} [options]
  15. * @returns {Boolean}
  16. */
  17. validate: function(validator, $field, options) {
  18. var value = $field.val();
  19. if (value === '') {
  20. return true;
  21. }
  22. // Email address regular expression
  23. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  24. var emailRegExp = /^(([^<>()[\]\\.,;:\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,}))$/;
  25. return emailRegExp.test(value);
  26. }
  27. };
  28. }(window.jQuery));