Jump to content

Question

Posted

Hi,

i'm trying to add an "input rule" in "universal module" to check if the field "url" is a specific subdomain.

 

I'm using this code in "input rules":

 

{"url":{
    "valid":{
        "rule": {"matches", "/^[\w.-]+\.midomain\.(com|it)$/"},
        "message":"URL is invalid"
    }
}}

But seems that no rule is applied so i can write anything in my "url" field.

 

Can someone help me, please?

 

Achille

3 answers to this question

Recommended Posts

  • 0
Posted

Not sure why I didn't see this sooner. You probably already discovered the issue, but when specifying parameters (the regex) to a callback ("matches"), an array format is expected. JSON arrays use brackets rather than braces, so the fix would be to simply change the rule from:

"rule": {"matches", "/^[\w.-]+\.midomain\.(com|it)$/"},

to

"rule": ["matches", "/^[\w.-]+\.midomain\.(com|it)$/"],
  • 0
Posted

You could only test adding/editing a service to see if the rules are validating by checking whether an error is generated. Is your Input Rule set for the Package or Service fields?

 

If you create a product with the following service field input rule:

{"hostname":{
    "valid":{
        "rule":"isEmpty",
        "negate":true,
        "message":"Hostname must not be empty"
    }
}}

..and you have a "hostname" service field set, you can check whether the rule validates by adding a service.

Go to add a service from the admin interface, select this product, and don't set a value for the hostname. When you click to Continue, an error should be shown saying "Hostname must not be empty". That will tell you whether the rules are validating. I tested this myself and find it to be working properly.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...