# phoneNumber Validation

**URL:** <https://forum.inductiveautomation.com/t/phonenumber-validation/44248>\
**Category:** General Discussion\
**Created:** [March 9, 2021, 4:58am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248 "2021-03-09T04:58:58Z")\
**Posts on this page:** 9\
**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 9, 2021, 4:58am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/1 "2021-03-09T04:58:58Z")

</div>

Hi guys, have a good days.

May I know that Ignition able to do the validation checking for phone number format which the users only able to insert number instead of alphabetic characters ?

---

<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 9, 2021, 10:28am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/2 "2021-03-09T10:28:47Z")

</div>

Vision or Perspective? Vision has the Formatted Text Field component which accepts a regex to limit input text. I don’t think there’s one yet for a Perspective

---

<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 10, 2021, 12:46am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/3 "2021-03-10T00:46:11Z")

</div>

Hi Bro nminchin, what I’m taking is for Perspective.

I see. So what can I do for Perspective for phoneNumber validation which accept only number instead of alphabetic characters ?

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 10, 2021, 4:15am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/4 "2021-03-10T04:15:55Z")

</div>

Nothing at the moment I don’t believe

---

<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 10, 2021, 4:17am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/5 "2021-03-10T04:17:50Z")

</div>

What if I use python phone number validation regex in Ignition. It is possible ?

---

<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 10, 2021, 4:56am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/6 "2021-03-10T04:56:24Z")

</div>

Of course,but you’ll have to post-process the value set by the user

---

<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 10, 2021, 5:00am UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/7 "2021-03-10T05:00:15Z")

</div>

May I know where is the best place to write the regex scripts ? Either Configure Events or Configure Scripts ?

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [March 11, 2021, 10:38pm UTC](https://forum.inductiveautomation.com/t/phonenumber-validation/44248/8 "2021-03-11T22:38:56Z")

</div>

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:

```auto
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.PhoneNumberFormat.NATIONAL)
		self.props.text = x
		self.custom.OK = 1
	else:
		self.custom.OK = 0
else:
	self.custom.OK = 0

```

Format is (222) 333-3456. You will need to import phononumbers, I think I got it here:

> **[phonenumbers](https://pypi.org/project/phonenumbers/)**
>
> Python version of Google's common library for parsing, formatting, storing and validating international phone numbers.

You will need to do your homework to make this work. I can’t help much more than what I wrote up in this post.

Edit, it should be noted, I don’t prevent characters, I only make sure what was entered is correct, hence the custom property “OK”.

---

<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/phonenumber-validation/44248/9 "2021-03-12T08:44:06Z")

</div>

Problem Solved. Thanks Brother
