1

Hi I am using bootstrapValidator. The Email validation count this emial@email valid instead of emial@email.com.

<div class="col-sm-4 form-group">
   <div class="error-icon">
      <label class="control-label">Email</label>
      <input class="form-control" id="person_email" name="person_email" placeholder="eg: youremail@gmail.com" type="email">
    </div>
</div>

Script

$('#basicBootstrapForm').bootstrapValidator({ 
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        person_email: {
            validators: {
               notEmpty: {
                   message: 'The email address is required'
               },
               person_email: {
                   message: 'The input is not a valid email address'
               }
           }
        },
    }
});

Any help would be appreciated.

Shehary
  • 9,926
  • 10
  • 42
  • 71
Skillie
  • 177
  • 2
  • 13
  • Possible duplicate of [Validate email address in JavaScript?](http://stackoverflow.com/questions/46155/validate-email-address-in-javascript) – TayTay Apr 11 '16 at 18:21

1 Answers1

3

you can use the regexp validator to define expression of email address.

regexp: {
  regexp: '^[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+$',
  message: 'The value is not a valid email address'
}

Validation script will be

$('#basicBootstrapForm').bootstrapValidator({
  feedbackIcons: {
    valid: 'glyphicon glyphicon-ok',
    invalid: 'glyphicon glyphicon-remove',
    validating: 'glyphicon glyphicon-refresh'
  },
  fields: {
    person_email: {
      validators: {
        notEmpty: {
          message: 'The email address is required'
        },
        regexp: {
          regexp: '^[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+$',
          message: 'The value is not a valid email address'
        }
      }
    },
  }
});

Fiddle

Shehary
  • 9,926
  • 10
  • 42
  • 71
  • Thank you very much I also added \.. after the second last +, so it validated the .com ^[^@\\s]+@([^@\\s]+\\.)+\..[^@\\s]+$ – Skillie Apr 12 '16 at 17:45
  • Thanks for this! I've noticed that capital letters are forbidden by default, is there a way to allow them through regexp? – Greg Apr 18 '16 at 19:45
  • `fasi@com.gmail`, `f@gmail.com.123`,`1@gmail.com.1111`, `a_b@b.g` I have checked these and it does accepts them – Moeez Jul 05 '22 at 13:12