Hi
I must create validations on a few fields on a form. One of the vaidation in a textfield is to find out if there are any other characters besides A-Z, a-z and - (hyphen) in a field. I would like to check this using @Formula language.
Which commands can I use to check a field for this?
Regards
Subject: Using Formula to find other characters the A-Z, a-z in a textfield
If @Matches doesn’t work another way is to use @ReplaceSubstring to replace the letter and hyphen with blanks and test if there is anything left. Something like
variable := @Trim(@ReplaceSubstring(fieldname; “A” : “a” : “B” : “b”; “” : “” : “” : “”));
@If(variable = “”; “Only Letters and hyphens”; “Something else”)
I haven’t tested this so the syntax may not be right and of course you will have to add all the letters and a corresponding number of “” to the @Replacesubstring.
Subject: Using Formula to find other characters the A-Z, a-z in a textfield
@Matches would probably be the right choice. Have a look at the documentation.
Regards,
Ruedi
Subject: RE: Using Formula to find other characters the A-Z, a-z in a textfield
Hi
I have looked at that function but the problemis that the text field length can vary a lot. The length of the text field can be 6, 7, 8 or more characters. Using this function requires me to know in front how many characters there are in the field.
How can i use this function to flexible test the textfield for other characters then A-Z, a-z and -?
Regards
Subject: RE: Using Formula to find other characters the A-Z, a-z in a textfield
Put a ±sign in front of the allowed characters to allow a variable number of characters.
This should be your solution:
@If(
@Matches(@ThisValue; “+{-A-Za-z}”);
@Success;
@Failure(“String contains invalid characters”))
Subject: RE: Using Formula to find other characters the A-Z, a-z in a textfield
Put a ±sign in front of the allowed characters to allow a variable number of characters.
This should be your solution:
@If(
@Matches(@ThisValue; “+{-A-Za-z}”);
@Success;
@Failure(“String contains invalid characters”))
Subject: Using Formula to find other characters the A-Z, a-z in a textfield
@Matches would normally do this for you, but I don’t think you can specify a hyphen in the patten. So we may have to replace the hyphens with a letter first. Note the + in the patten to match any number of characters.
no_hyphens := @ReplaceSubstring( My_Field ; “-” ; “A” );
@Matches( no_hyphens ; “{+A-Za-z}” )
Subject: RE: Using Formula to find other characters the A-Z, a-z in a textfield
You can put a hyphen in the pattern. It has to be the first character in the pattern.
e.g. “+{-A-Za-z0-9}” to allow characters A to z, numbers and hyphen.