Jump to content
  • 0

Validate Email In Input Rules


AllanD

Question

I am trying to understand how the examples in Error Checking (http://docs.blesta.com/display/dev/Error+Checking)relate to the JSON formated version of Input Rules in the Universal Module.  All the examples in Error Checking are php arrays.  The simple examples seem obvious, but how would the ones with functions be done in Input Rules?

 

What is the correct way to validate an email address given the Service Option of admin_email?

{
"admin_email":{
    "valid":{
        "rule":["filter_var",["admin_email","FILTER_VALIDATE_EMAIL"]],
        "message":"Please enter a valid email address."
    }
  }
}

The above fires but fails with a valid address in the field.

 

Why aren't there more examples in the docs for the JSON formatted Input Rules?

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Your rule looks syntactically correct. However, php's filter_var function does not return boolean unless the filter fails. Since it usually returns a string, and all non-empty strings are evaluated boolean true, your rule wouldn't suffice for email validation.

 

The Input component has its own email validation method. It was likely added after the documentation you referenced was created.

 

Try:

{
"admin_email":{
    "valid":{
        "rule":"isEmail",
        "message":"Please enter a valid email address."
    }
  }
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...