How does one modify the attached script to check for

Hi,

How does one modify the attached script to check for the highlighted regular expression?

Thanks

  • Mun

    <script type="text/javascript">
    (function(Views, Models, $, Backbone) {
    Views.AuthModal.prototype.doRegister: function(event) {
    event.preventDefault();
    event.stopPropagation();
    this.register_validator = $("form#signup_form").validate({
    rules: {
    username: "required",
    password: "required",
    email: {
    required: true,
    email: true
    },
    re_password: {
    required: true,
    equalTo: "#password1"
    }
    },
    messages: {
    username: qa_front.form_auth.error_msg,
    password: qa_front.form_auth.error_msg,
    email: {
    required: qa_front.form_auth.error_msg,
    email: qa_front.form_auth.error_email,
    },
    re_password: {
    required: qa_front.form_auth.error_msg,
    equalTo: qa_front.form_auth.error_repass,
    }
    }
    });

    var form = $(event.currentTarget),
    username = form.find('input#username').val(),
    email = form.find('input#email').val(),
    button = form.find('input.btn-submit'),
    password = form.find('input#password1').val(),
    data = form.serializeObject(),
    view = this;

    if (this.register_validator.form() && !form.hasClass('processing')) {
    this.user.register(data, {
    beforeSend: function() {
    view.blockUi.block(button);
    form.addClass('processing');
    },
    success: function(user, status, jqXHR) {
    view.blockUi.unblock();
    form.removeClass('processing');
    view.closeModal();
    if (status.success) {
    AE.pubsub.trigger('ae:notification', {
    msg: status.msg,
    notice_type: 'success',
    });
    window.location.href = status.redirect;
    } else {
    AE.pubsub.trigger('ae:notification', {
    msg: status.msg,
    notice_type: 'error',
    });
    }
    }
    });
    }
    },
    doSendPassword: function(event) {
    event.preventDefault();
    event.stopPropagation();
    this.forgot_validator = $("form#forgotpass_form").validate({
    rules: {
    email: {
    required: true,
    email: true
    },
    },
    messages: {
    email: {
    required: qa_front.form_auth.error_msg,
    email: qa_front.form_auth.error_email,
    },
    }
    });

    var form = $(event.currentTarget),
    email = form.find('input#email').val(),
    button = form.find('input.btn-submit'),
    view = this;

    if (this.forgot_validator.form()) {
    this.user.forgot(email, {
    beforeSend: function() {
    view.blockUi.block(button);
    },
    success: function(user, status, jqXHR) {
    view.blockUi.unblock();
    view.closeModal();
    var success = status.success ? 'success' : 'error';
    AE.pubsub.trigger('ae:notification', {
    msg: status.msg,
    notice_type: success,
    });
    }
    });
    }
    }
    });

    Views.ResetPassModal = AE.Views.Modal_Box.extend({
    events: {
    'submit form#resetpass_form': 'doResetPassword',
    },
    initialize: function() {
    AE.Views.Modal_Box.prototype.initialize.call();
    this.blockUi = new AE.Views.BlockUi();
    this.user = new Models.User();
    },
    doResetPassword: function(event) {
    event.preventDefault();

    this.reset_validator = $("form#resetpass_form").validate({
    rules: {
    new_password: "required",
    re_new_password: {
    required: true,
    equalTo: "#new_password"
    }
    },
    messages: {
    new_password: qa_front.form_auth.error_msg,
    re_new_password: {
    required: qa_front.form_auth.error_msg,
    equalTo: qa_front.form_auth.error_repass,
    }
    }
    });

    var form = $(event.currentTarget),
    regex ='/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.co\.uk)|(\.uk)$/',
    username = form.find('input#user_login').val(),
    user_key = form.find('input#user_key').val(),
    new_password = form.find('input#new_password').val(),
    button = form.find('input.btn-submit'),
    view = this;

    if (this.reset_validator.form()) {
    this.user.resetpass(username, new_password, user_key, {
    beforeSend: function() {
    view.blockUi.block(button);
    },
    success: function(user, status, jqXHR) {
    view.blockUi.unblock();
    view.closeModal();
    if (status.success) {
    AE.pubsub.trigger('ae:notification', {
    msg: status.msg,
    notice_type: 'success',
    });
    window.location.href = status.redirect;
    } else {
    AE.pubsub.trigger('ae:notification', {
    msg: status.msg,
    notice_type: 'error',
    });
    }
    }
    });
    }
    }
    });
    }
    })(QAEngine.Views, QAEngine.Models, jQuery, Backbone);
    </script>

  • Ash

    Hello @Mun

    I hope you are well today.

    You can use this simple function:

    function checkEmil(email) {
        regex =/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.co\.uk)|(\.uk)$/;
        return regex.test(email)
    }

    So, when you get any email, just pass as the parameter of that function, if it validates it should return true, otherwise false.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • Mun

    Hi@Ash

    I have tried this ` var email = function (form.find('input#email').val()) { var regex =/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.co\.uk)|(\.uk)$/;
    return regex.test(email)};
    var form = $(event.currentTarget),
    button = form.find('input.btn-submit'),
    view = this;

    if (this.forgot_validator.form()) {
    this.user.forgot(email, {
    beforeSend: function() {
    view.blockUi.block(button);
    },
    success: function(user, status, jqXHR) {
    view.blockUi.unblock();
    view.closeModal();
    var success = status.success ? 'success' : 'error';
    AE.pubsub.trigger('ae:notification', {
    msg: status.msg,
    notice_type: success,
    });
    }
    });
    }`

    but it is not working.. How do i get about getting to work#?

    Thanks

  • Ash

    Use the following code as an external script:

    jQuery(function($) {
      $('.btn-submit').click(function(e){
        var email = $('#email').val();
        if(checkEmil(email)){
          return true;
        }
        else{
          alert('Your email is not valid');
          e.preventDefault();
          return false;
        }
      });
    });
    
    function checkEmil(email) {
        regex =/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.co\.uk)|(\.uk)$/;
        return regex.test(email)
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.