0

I am using jquery.validate.js by Jörn Zaefferer.

All validation is set up perfectly with the following code:

$("#homeForm").validate({
    rules: {
          email: {
                   required: true,
                   email: true                             
          },
          mobile:{
                  required:true,
                  minlength:11,
                  maxlength:11,
          }
    },
 });

My problem is that the default email validation will allow the user to leave out the domain suffix, for example test@test is validated successfully...

I would like my email validation to require the user to include the domain suffix of the email they input (.com, .co.uk ETC)

Does anyone have a solution for this problem? Many thanks in advance...

Sparky
  • 98,165
  • 25
  • 199
  • 285
JamesHusband
  • 51
  • 1
  • 10
  • I use that script, it doesn't let me typ `test@test`. – Barmar Oct 30 '14 at 10:06
  • @Barmar http://jsfiddle.net/arunpjohny/qvm047hw/1/ - what is the version you are using? even in 1.13.0 the same error is there - [1.13.0](http://jsfiddle.net/arunpjohny/qvm047hw/2/) – Arun P Johny Oct 30 '14 at 10:08
  • My application uses 1.10.0, maybe it changed since then? – Barmar Oct 30 '14 at 10:11
  • I am using version v1.13.1 – JamesHusband Oct 30 '14 at 10:12
  • Looks like it changed in 1.11.0. The comment in the code says if you have a problem with the current implementation, report a bug against the spec at https://html.spec.whatwg.org/multipage/forms.html#e-mail-state-(type=email) – Barmar Oct 30 '14 at 10:16
  • 1
    There's nothing that prevents the operator of a top-level domain from providing mail service, so `user@uk` would be a valid email if the UK government decided to accept mail there. – Barmar Oct 30 '14 at 10:20

1 Answers1

-2

So I seem to have found a solution with a little digging through the .js file:

I changed the default email rule from:

        email: function(a, b) {
            return this.optional(b) || /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(a)
        },

to:

        email: function(a, b) {
            return this.optional(b) || /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(a)
        },

It now works perfectly, bit of strange bug but I hope this helps others who found the same problem

JamesHusband
  • 51
  • 1
  • 10