Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Custom JQuery Validation methods VS HTML validation #6467


User avatar
0
martin created

I added a Custom JQuery Validation method :-

    $.validator.addMethod("ABN", function (value, element) {
        return /[0-9]{12}/.test(value);
    }, "Please enter a valid ABN.");
    
    this.init =
    .
    .
                $('#SuperFund_FundABN').rules("add", {
                ABN: true
            });

Which results in a 'nice' validation for my user.

Where as what has been autogenerated by the RAD tool :-

<input class="form-control" id="SuperFund_BSB" value="@Model.SuperFund.BSB" type="text" name="bsb" maxlength="@epayday.Epayday.SuperFunds.SuperFundConsts.MaxBSBLength" minlength="@epayday.Epayday.SuperFunds.SuperFundConsts.MinBSBLength" pattern="@epayday.Epayday.SuperFunds.SuperFundConsts.BSBRegex" />

Results with a modal message.

Which provides an inconsistant user experience.

Am I missing something fundamental ? Or do I have to create custom JQuery Validation methods for regular expressions ?


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @martin,

    The regex when you entered on RAD tool and the one one on the client side is not the same I guess. You can compare the value of epayday.Epayday.SuperFunds.SuperFundConsts.BSBRegex (server side const) with the one you are using on the client side [0-9]{12}

    The one on the server side is [0-9]{6} I guess. You need to make them same.

  • User Avatar
    0
    martin created

    In my original question I was showing the two validation methods for two differnt different HTML inputs.

    A better way to have asked this question would be :-

    If I add pattern="[0-9]{6-12}" to a HTML input what extra do I need to get the JQuery Validator to validate that value ?

    Do I create my own custom JQuery Validation method (a per my original question) ? OR am I missing something obvious ?

    Keep in mind the pages I am updating were generated by the RAD tool.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @martin,

    It seems like pattern attribute on the input doesn't work. Could you create an issue on https://github.com/aspnetzero/aspnet-zero-core/issues ?

  • User Avatar
    0
    martin created

    I'm having trouble getting access to your git-hub and I will be away for 1 week so I'll have to raise that when I get back.

  • User Avatar
    0
    ismcagdas created
    Support Team

    You can add your GitHub user on https://aspnetzero.com/LicenseManagement

  • User Avatar
    0
    martin created

    Got back from my holidays and created an issue in GitHub as requested.

    #<span></span>2218 martin-epayday

  • User Avatar
    0
    aaron created
    Support Team