# Format Text Field

**URL:** <https://forum.inductiveautomation.com/t/format-text-field/44347>\
**Category:** General Discussion\
**Created:** [March 11, 2021, 3:47am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347 "2021-03-11T03:47:40Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![tohhy-pm17](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tohhy-pm17](https://forum.inductiveautomation.com/u/tohhy-pm17)\
**Post date:** [March 11, 2021, 3:47am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/1 "2021-03-11T03:47:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 11, 2021, 6:40am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/2 "2021-03-11T06:40:47Z")

</div>

You should use the Numeric Entry Field instead of the Text Field.  
 ![Screen Shot 2021-03-10 at 10.40.32PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/79feb7724470578d1263ba01138c4da2325c6a08.png)

---

<div class="post-metadata">

**Author:** ![tohhy-pm17](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tohhy-pm17](https://forum.inductiveautomation.com/u/tohhy-pm17)\
**Post date:** [March 11, 2021, 9:11am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/3 "2021-03-11T09:11:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 11, 2021, 1:49pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/4 "2021-03-11T13:49:11Z")

</div>

You already asked the same question in another topic…

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 11, 2021, 9:22pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/5 "2021-03-11T21:22:24Z")

</div>

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:

 ![Screen Shot 2021-03-11 at 1.14.57PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/16fdc6c25d4c1ec0ea4e5febed56c3c6e1fc69eb.png)

After focus is lost:

 ![Screen Shot 2021-03-11 at 1.15.05PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/3/033e30bd19d8325a2d000621dcb4b0341163aec6.png)

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:

 ![Screen Shot 2021-03-11 at 1.20.37PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/379b370fecb143e98ab9293362aff1950a6dedaa.png)  
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.

---

<div class="post-metadata">

**Author:** ![tohhy-pm17](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tohhy-pm17](https://forum.inductiveautomation.com/u/tohhy-pm17)\
**Post date:** [March 12, 2021, 8:44am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/6 "2021-03-12T08:44:25Z")

</div>

Problem Solved. Thanks ALL.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 12, 2021, 4:17pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/7 "2021-03-12T16:17:22Z")

</div>

How did you solve it?

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [March 12, 2021, 5:01pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/8 "2021-03-12T17:01:21Z")

</div>

It looks like this did the trick for OP:

> [@phoneNumber Validation](http://forum.inductiveautomation.com/t/phonenumber-validation/44248/8):
>
> I used a text field to enter phone numbers. I used a change script, right click on text property add change script. This is my script, it’s not the best and could probably be better, but did what I wanted: import phonenumbers import re x = currentValue.value regex = "^\(?\d{3}\)?[-]?\d{3}[-]?\d{4}$" if re.search(regex,x): z = phonenumbers.parse(x, "IN") if phonenumbers.is\_valid\_number(z): x = phonenumbers.format\_number(phonenumbers.parse(self.props.text, 'US'), phonenumbers.PhoneNumb…

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 13, 2021, 9:39pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/9 "2021-03-13T21:39:40Z")

</div>

They “just did” 😉

---

<div class="post-metadata">

**Author:** ![tohhy-pm17](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tohhy-pm17](https://forum.inductiveautomation.com/u/tohhy-pm17)\
**Post date:** [March 15, 2021, 12:57am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/10 "2021-03-15T00:57:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 15, 2021, 3:01pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/11 "2021-03-15T15:01:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tohhy-pm17](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tohhy-pm17](https://forum.inductiveautomation.com/u/tohhy-pm17)\
**Post date:** [March 16, 2021, 12:50am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/12 "2021-03-16T00:50:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Esme\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@Esme\_Lopez](https://forum.inductiveautomation.com/u/Esme_Lopez)\
**Post date:** [March 9, 2022, 4:02pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/13 "2022-03-09T16:02:38Z")

</div>

What kind of event?

---

<div class="post-metadata">

**Author:** ![Purushothaman\_R](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Purushothaman\_R](https://forum.inductiveautomation.com/u/Purushothaman_R)\
**Post date:** [September 20, 2023, 9:09am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/14 "2023-09-20T09:09:21Z")

</div>

> [@cmallonee](#):
>
> here’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:

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

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 20, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/15 "2023-09-20T14:42:09Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [September 21, 2023, 9:24am UTC](https://forum.inductiveautomation.com/t/format-text-field/44347/17 "2023-09-21T09:24:05Z")

</div>

Response to new question above moved to

> [@Need to make sure text or numbers are entered in components](https://forum.inductiveautomation.com/t/need-to-make-sure-text-or-numbers-are-entered-in-components/79441/5):
>
> so my requirement is if a user try to type alphanumeric values or numbers ... Numbers are alphanumeric. ... I need a togglepopup to be opened stating "Only strings are allowed" so that user can know only strings are allowed. Everything you can type is a string so that prompt wouldn't help anyone. Anyway, don't do that. Use standard web interface so that your application works as the users expect. For example, Set the border of each text field to red and change to black when the field h…
