Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Field Validation

Avatar

Former Community Member

Hi There,  I am trying to validate a text field in a form that I have created. The field valiadtion works initially and the code executes as required.  Though once the code has run and I edit the text field again the validation  does not occur a second time around and will allow me to submit any  form of data.  Here is the code that I am using in the Textbox:   root.P1.client.variable_option_client.cv7::change - (FormCalc, client) if(root.P1.matched.Consent.rawValue == 1) then    if(root.P1.client.variable_option_client.cv6.rawValue == null or root.P1.client.variable_option_client.cv7.rawValue == null)      then           root.P1.matched.EmailSubmitButton2.presence = "invisible"            root.P1.matched.EmailSubmitButton2[1].presence = "invisible"           root.P1.matched.Consent.rawValue = 0     endif endif   I would like to know how I can get the Textbox to validate the field and the amount of  digits in it.  I have specified in the objects validation options a value of :  text{9999999999}  But like I say this does not work more than once.  Please help  J

3 Replies

Avatar

Level 10

Hi,

I am trying to understand what data input you are allowing in cv7. Is the user allowed to enter text or just numeric values?

The script does not seem to be set up to check/validate the actual input of cv7, merely set the presence of other objects based on cv7 not being null. For this I would not use the change event, which fires each time the user inputs a character. Instead I would use the exit event, as this is when the full input into the field is registered with the cv7 field.

If you want to limit the input, you can select cv7 and go to the Object > Field palette where you can set the max characters to 10 characters.

There are scripts on the forums that use the change event to look at each character as it is entered and if it is not the right type (eg alphabetic character or numeric character) then it does not input it. Search for Reg Expression.

Maybe if you could outline what you are trying to achieve with cv7.

Niall

Assure Dynamics

Avatar

Former Community Member

Hi Niall,

In cv7 I would like to enter only a numneric value with the maximum number

of numbers allowed to be 10.

So you say that if i use the exit field this will prevent incorrect values from being

submitted?

Thanks I will search for it now and see what I come across.

Your help is much appreciated.

Thanks

J

Avatar

Level 10

Hi,

There are a couple of approaches.

If you are using a numericField then you could set the numericfield to have a comb of 10 characters. See the Object > Field palette. This automatically gives a solid box border, which may not suit your layout/design. However this is the most reliable solution, without script.

If you use a textfield, you can also limit the number of characters to 10, in the Object > Field palette. But this time you can keep a 3D border to the field. However you will need a little script in the change event that prevents alphabetic characters from being accepted in the field:

var vPattern = /[a-z]/;

var result = vPattern.test(xfa.event.newText);

if (result == true)

{

     xfa.event.change = "";

     xfa.host.beep("0");

}

Hope that helps,

Niall

Assure Dynamics