# 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:** 1\
**Showing post:** 8

<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”.

---

_[View the full topic](https://forum.inductiveautomation.com/t/phonenumber-validation/44248)._
