cancel
Showing results for 
Search instead for 
Did you mean: 

How to make permission to enter Only Digits in String Context Attribute?

Former Member
0 Kudos

1. It is necessary to allow entry into InputField only digits.

2. The number of digits is limited to 5.

There is a context attribute "Code" of type string.

I have a code:


ISimpleTypeModifiable attributeType = wdContext.nodeCreateParams (). GetNodeInfo (). GetAttribute ( "Code"). GetModifiableSimpleType ();
attributeType.setMaxLength (5);

But I do not know how to allow entry only digits.

I would be grateful for your help!

Accepted Solutions (1)

Accepted Solutions (1)

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Vitaly

The problem is you cannot apply a format pattern to String based simple type.

The restriction can be overcame if you make the attribute Calculated. Then in setter-method you can perform the string parsing according to your 5-digits rule. For the purpose you can use Java class MessageFormat.

If the input string coming to the setter does not follow to the 5-digits rule, report the corresponding error message using method:

wdComponentAPI.getMessageManager().raiseInvalidContextAttributeMessage(...);

Hope this will help you.

BR, Siarhei

Answers (3)

Answers (3)

Former Member
0 Kudos

Thank you for your answers and your help!

Former Member
0 Kudos

The problem is How to make permission to enter Only Digits in String Context Attribute?

Now user can enter strings like:

abcde

gu4.%8

etc.

And I need to prohibit entry of non-numeric characters

Former Member
0 Kudos

Hi,

I doubt if you can restrict user from entering numeric value for a String type attribute. You can always perform validation on some action in your code.

eg. wdContext.currentContextElement.get<attributevalue>.matches("[0-9]*"); to verify if the string contains only digits.

Regards,

MK

p330068
Active Contributor
0 Kudos

I think you need to write onEnter Events method for your input field to restrict users for entering other value than neumeric values.

Hope this will help you.

Thanks

Arun

p330068
Active Contributor
0 Kudos

Hi

1. It is necessary to allow entry into InputField only digits. -


2. The number of digits is limited to 5.----


it depends on you requirement

Create Simple Type (with String and length Constrints>here you can specify max and min length) in the Dictionary.

Assign it to attribute you have created in Context.

Hope this will helps you.

Thanks

Arun