Attribute Rule to Prevent Punctuation In a Field

162
1
Jump to solution
2 weeks ago
Labels (1)
ElisseDeleissegues1
New Contributor III

I would like to create an attribute rule that prevents punctuation in specific fields.

There are plenty of examples on Must Not be Null, Must Have a Record, Must have x # of characters, etc. and I am using many of them.

This solution contains a way to find characters, but what I need is for there to be an error message that alerts the user that the field should not contain certain characters.

https://community.esri.com/t5/arcgis-pro-questions/attribute-constraint-rule-limit-characters/td-p/1...

I would like to prevent punctuation ex  ".", ",", ":" (period, comma, colon) in specific fields, sometimes more than one of these and sometimes just one.

I haven't been able to find a function or an example that would help.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DrewDowling
Occasional Contributor III

You could create a constraint attribute rule that tests fields for punctuation and returns an error if found—something like this where NoPuctuation is the name of the attribute you are trying to constrain.

var testVal = $feature.NoPuctuation
if (Find (",", testVal) > -1)
    return   {"errorMessage": "Comma Found."}
else if (Find (".", testVal) > -1)
    return   {"errorMessage": "Period found."} //asas
else if (Find (":", testVal) > -1)
    return   {"errorMessage": "Colon found."}
else
    return true;

 

View solution in original post

0 Kudos
1 Reply
DrewDowling
Occasional Contributor III

You could create a constraint attribute rule that tests fields for punctuation and returns an error if found—something like this where NoPuctuation is the name of the attribute you are trying to constrain.

var testVal = $feature.NoPuctuation
if (Find (",", testVal) > -1)
    return   {"errorMessage": "Comma Found."}
else if (Find (".", testVal) > -1)
    return   {"errorMessage": "Period found."} //asas
else if (Find (":", testVal) > -1)
    return   {"errorMessage": "Colon found."}
else
    return true;

 

0 Kudos