Format Text Field

Hi Guys, I am new to Ignition and currently I faced some problems. Hope I can get your helps.

It is possible to format the text field which only allows the users to insert numeric instead of alphabetical characters. Currently I’m using the perspective modules so it is possible to do that ?

Thanks in advance

You should use the Numeric Entry Field instead of the Text Field.
Screen Shot 2021-03-10 at 10.40.32PM

Hi Bro cmallonee,

I cant use the Numeric Entry Field because what I want is let the user to insert their contact number so Numeric Entry Field is not the option for me. You get it what I means ? Therefore, what should I do in order to format the text field that only accept numbers. For instance, 01589652586.

Thanks in advance.

You already asked the same question in another topic…

There’s no way to prevent a user from entering characters in a Text Field. You can prevent string characters from being placed into the value with smart logic in a value change script, but again, that won’t prevent a user from putting characters into the Text Field. So using this route you’ll encounter a difference between what is displayed and what the true value is until focus is lost, at which point the component will display the true value.

User is able to supply invalid characters, but the change script is writing the last “valid” value to props.text whenever an invalid character is supplied:

After focus is lost:

I don’t understand why the Numeric Entry Field can’t be used for a contact number… If you modify the props.format property to be 00000000000, then you can have your contact number displayed in it:


The value is not exact, so I guess I could see where that might be your problem, but you just need to account for that in whatever write action you have by prepending 0 the the value as necessary.

Problem Solved. Thanks ALL.

How did you solve it?

It looks like this did the trick for OP:

They “just did” :wink:

Hi Bro cmallonee, I actually used the normal Python code to solve the problem.

phone_number.isdigit() == False or len(phone_number) > 12:

This is my sample code.

But how did you apply that to the Text Field? As part of a change script?

Hi Bro cmallonee, I actually apply it at the button event configuration.

What kind of event?

Hi cmallonee, i am new to ignition ,using 8.1 can you say how we can make text field component to accept only alphabets i tried my best but i am not able to solve it. can you kindly elaborate

There is no mechanism to ignore invalid characters or prevent them from being typed into the Text Field or Text Area components. All capturing, handling, and sanitizing is done on the back-end, through change scripts and binding rules you apply.

To enforce alpha values through the change script:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
    if currentValue and currentValue.value not in [None, ""]:
        if not currentValue.value.isalpha()
            self.props.text = previousValue.value

Now, as mentioned, this still executes after the user has supplied some text value, so they might have typed something like "alphab3tic", where the 3 should have been disallowed. One minor trick to prevent the field from showing "alphab3tic" due to the disallowed 3 character is to set TextField.props.deferUpdates AND TextField.props.rejectUpdatesWhileFocused to False. Doing so (with the same change script applied) will validate each character as it is typed, resulting in the 3 being ignored after it has been typed. As you are no longer rejecting updates while focused, the front-end session is displaying the sanitized value.

Response to new question above moved to