Jump to content

Question

Posted

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?

 

2 answers to this question

Recommended Posts

  • 0
Posted

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."
    }
  }
}

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...