# How to detect only spaces in text field

**URL:** <https://forum.inductiveautomation.com/t/how-to-detect-only-spaces-in-text-field/14001>\
**Category:** Ignition\
**Created:** [April 7, 2017, 10:09pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-only-spaces-in-text-field/14001 "2017-04-07T22:09:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robot\_B9](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robot_b9/32/3599_2.png) [@Robot\_B9](https://forum.inductiveautomation.com/u/Robot_B9)\
**Post date:** [April 7, 2017, 10:09pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-only-spaces-in-text-field/14001/1 "2017-04-07T22:09:28Z")

</div>

I have a text field that is being used to update a database table. I only want to write when there is readable text entered.

How can I prevent the write if the text field has only “spaces”?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 7, 2017, 11:15pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-only-spaces-in-text-field/14001/2 "2017-04-07T23:15:38Z")

</div>

Try using python’s strip() method of strings, something like:`if event.propertyName=='text':
   if len(event.newValue.strip()):
      system.db.runPrepUpdate(".....", [event.newValue])`

---

<div class="post-metadata">

**Author:** ![Robot\_B9](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robot_b9/32/3599_2.png) [@Robot\_B9](https://forum.inductiveautomation.com/u/Robot_B9)\
**Post date:** [April 18, 2017, 2:46pm UTC](https://forum.inductiveautomation.com/t/how-to-detect-only-spaces-in-text-field/14001/3 "2017-04-18T14:46:03Z")

</div>

Thanks

The len() and strip() methods worked great!

My code

```
varChkDesc1 = event.source.parent.getComponent('Text Field 1').text
if len(varChkDesc1.strip(' '))== 0:
	varChkDesc1 = 'n/a'
```
