1

I don't know how to add custom rules in SMOKE validation plugin. For example I want to add validate username. I know that how to validate username. But, I want to know that how to add that rules in that plugin. this is the code I've written

$('#login-submit').click(function (e) {
        e.preventDefault();
        if ($('#login-form').smkValidate()) {
            $.smkAlert({
                text: 'You logged in successfully!',
                type: 'success'
            });
        }
    });

and this is the function created to validate username. it returns false if username is not valid.

function isUsernameValid(username) {
    return /^[0-9a-zA-Z_.-]+$/.test(username);
 }

so how can i insert a custom rule to this script if i want to. Thank you!

mega6382
  • 9,211
  • 17
  • 48
  • 69

1 Answers1

0

you should use data-smk-pattern attribute for the username input

in your case:

<input type="text" class="form-control" data-smk-pattern="^[0-9a-zA-Z_.-]+$">

you can also refer to the smoke documentation: http://alfredobarron.github.io/smoke/#/validate#pattern

t2n
  • 48
  • 5
  • Yes it's working. Thx for your help. So we can't add our own script anyhow? @t2n – Digvijay Rathod Oct 02 '17 at 16:03
  • I didn't see that kind of feature in the docs, it might be worth writing that functionality yourself and sending a PR, or at least mentioning the need in the issues :) cheers – t2n Oct 02 '17 at 16:42