Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Is there a way to do an "Or" in the Edit Pattern?

Avatar

Former Community Member
For example, the social security number field. I want to be able to do numeric{999-99-9999}|numeric{999999999} in the Numberi Field type. Is this possible? Or do I have to change the type to Field Text?
9 Replies

Avatar

Former Community Member
Okay, I found that this, 999-99-9999|999999999, works for the "Or" in Numeric Type field but then if I type in "12a-74-6789" and hit the tab on my keyboard, it's not giving me a pop error. Instead, the field automatically change the value to all zeros or just the last 4 numeric digits. If it is a numeric type field, it should give me an error when I type in a character in the field, correct? Help is appreciated.

Avatar

Former Community Member
You cannot type any characters in a numeric field except for numbers. If you do it will reset the value to 0's automatically, and it does this before validate, so it won't give you an error.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
So how do I prevent the user from typing a character? I tried using the Text Field type and again, it resets back before the value gets validated.

Avatar

Former Community Member
You'll definately need to use a text field to display any non-numeric characters.



I'd use a validation script on the field that uses regular expressions. You can check an online JavaScript tutorial to see how to use regular expressions. Ending a validation script with a false; will make it fail validation, true; will make it pass, and you can customize the error message to display to the user whatever you want.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
I do not want to use any non-numeric characters that is why I choose to use Numeric Type instead of Texts type. I want to prevent people from typing a string character into the field with a pop up error message. I have tried both the numeric and text type and both just reset the value instead of giving a pop up error message.

Avatar

Former Community Member
By the way, can you point me to that tutorial you're reffering to? I couldn't find it on the adobe website.

Avatar

Former Community Member
'-' is a non-numeric character.



I wasn't refering to any Adobe tutorial. Regular expressions are standard JavaScript not Adobe specific. If you do a google search I'm sure you'll find a number of tutorials online.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thanks! I'll do some google search. However, I believed that the value is still numeric, the "-" is only for displaying. If it is not numeric, Adobe Designer would have given me an error when I'm when defining pattern in a Numeric Type field.

Avatar

Former Community Member
Good point, you're right about the '-' being fine in the display pattern. Wasn't thinking straight :p



Chris

Adobe Enterprise Developer Support