2

I'm new to APEX and was writing a validation function for a field called DESIGNATION. I have the REGEX that that looks like this:

(^[a-zA-Z0-9][a-zA-Z0-9=.\-\/\s+]{1,49})

The designation field must begin with an a-z, A-Z or 0-9 and be followed by 1 to 49 more characters that are a-z, A-Z, 0-9 an equal sign, a period, a hyphen, a backslash, or a space character. This field must be one character long and can be a total of 50 characters long.

Here is a screen shot of the validation screen:

Page Validation

When I go to run my app on the screen called SYNOPTIC with the designation field on it to validate and type "AZC A }{}##" which has the bad characters of '}{}##' in it, it allow the row to be updated and shouldn't

UI

So my question is, is it the regular expression that is the issue or the Type field being "Item/Column in Expression 1 matches Regular Expression in Expression 2", or a combination of both? If my regular expression is bad then how do I fix it?

  • Just a note, field names cannot start with a number. – Adrian Larson Apr 28 '17 at 16:22
3

The dot has a special meaning in regular expressions and so any character is valid. You need to escape the dot with a backslash for it to work. Moreover you stated that a backslash should be matched, but your expression would match a forward slash instead. To change this you need to replace \/ with \\. Altogether this leads to something like this:

(^[a-zA-Z0-9][a-zA-Z0-9=\.\-\\\s+]{1,49})

A good resource to test regular expressions that also gives a detailed explanation of the current meaning of the expression is regular expressions 101

  • Thanks for the link, Markus. Well, I even reduced my expression down to ([A-Z,0-9]{1,50}) and it still allows bad characters such as #${} into my designation field. I think that it is an issue with getting the right Type and the right Condition Type field to sync up with my regex. I have a Type of "Item/Column in Expression 1 matches Regular Expression in Expression 2", and a Condition Type of "Always" set for whenever the SUBMIT (Save Changes) button is pressed. So my question now becomes, do I have the right settings for my regex? – Janet May 1 '17 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.