mathenthusiast8203
mathenthusiast8203

Reputation: 865

How to do custom validation in Semantic UI?

In Semantic UI, I already know that you can validate forms, but there are only certain rules you can validate. In my signup form (in my application), I want to check if a user with a certain email already exists in the server. If the email exists, the user cannot signup with that certain email. How would I achieve this?

Upvotes: 6

Views: 5280

Answers (1)

Nighisha John
Nighisha John

Reputation: 409

You can add custom validation rules to your form.

$.fn.form.settings.rules.myCustomRule = function(param) {
    // Your validation condition goes here
    return (param <= 10 )? true : false;
}

To pass parameters to a rule, use bracket notation in your settings object.

 rules: [
         {
           type   : 'myCustomRule[param]',
           prompt : 'Custom Error'
         }
       ]

Here is the doc Adding custom validation rule in semantic

Upvotes: 8

Related Questions