<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can I check if a string has numbers (0-9) and dashes? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230149#M17846</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A snippet from Mark Pilgrim's "Dive into Python", chapter 7 about the re module..&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Regular expressions are extremely powerful, but they are not the correct solution for every problem. You should learn&lt;BR /&gt;enough about them to know when they are appropriate, when they will solve your problems, and when they will cause&lt;BR /&gt;more problems than they solve.&lt;BR /&gt;Some people, when confronted with a problem, think "I know, I'll use regular expressions."&lt;BR /&gt;Now they have two problems.&lt;BR /&gt;�??�??Jamie Zawinski, in comp.emacs.xemacs&lt;BR /&gt;(&lt;A href="http://groups.google.com/groups?selm=33F0C496.370D7C45%40netscape.com"&gt;http://groups.google.com/groups?selm=33F0C496.370D7C45%40netscape.com&lt;/A&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All the stuff about parsing phone numbers etc is in there. But re expressions just give me a headache...!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But well done for the answer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Aug 2013 05:57:16 GMT</pubDate>
    <dc:creator>NeilAyres</dc:creator>
    <dc:date>2013-08-07T05:57:16Z</dc:date>
    <item>
      <title>How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230141#M17838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How can I check if a string has numbers (0-9) and dashes? The user will type a phone number, but I want to make sure he doesn't enter letters, just numbers and dashes. I already wrote code to make sure it is the right size (12 characters) and the dashes are in the right order, but I want to restrict the string to have no letters. Thank you!!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def updateMessages(self, parameters): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the messages created by internal validation for each tool &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parameter.&amp;nbsp; This method is called after internal validation.""" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Status = parameters[0] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #this can only be included if the field is not optional: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone = parameters[12] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Phone.value: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phonetxt = Phone.value &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(Phonetxt) &amp;lt; 12: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(Phonetxt) &amp;gt; 12: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not "-" in Phonetxt: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630")&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(Phonetxt) == 12: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phone3dig = Phonetxt[0:4] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not "-" in phone3dig: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phone32dig = Phonetxt[0:3] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "-" in phone32dig: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phone6dig = Phonetxt[4:8] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not "-" in phone6dig: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phone62dig = Phonetxt[4:7] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "-" in phone62dig: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phone12dig = Phonetxt[8:] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "-" in phone12dig: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Aug 2013 14:02:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230141#M17838</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-08-06T14:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230142#M17839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def updateMessages(self, parameters): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; import re &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phonenumber_format = re.compile("\d{3}-\d{3}-\d{4}") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone = parameters[12] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Phone.value: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; not phonenumber_format.match(Phone.value): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Aug 2013 14:35:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230142#M17839</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-08-06T14:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230143#M17840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may be clumsy, but 1 way to get the job done:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...load a list 0-9:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; allowed = []
&amp;gt;&amp;gt;&amp;gt; for i in range(10):
 allowed.append(str(i))

 
&amp;gt;&amp;gt;&amp;gt; print allowed
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...also, load the hyphen:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; allowed.append('-')
&amp;gt;&amp;gt;&amp;gt; print allowed
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-']
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...then, let's say you have a phone number, inadvertently has an 'e' in it, then it must pass the following test:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; txt = '4e6-234-2345'
&amp;gt;&amp;gt;&amp;gt; for each in txt:
 if each in allowed:
&amp;nbsp; pass
 else:
&amp;nbsp; print 'whoa...' + each + ' not allowed'

&amp;nbsp; 
whoa...e not allowed
&amp;gt;&amp;gt;&amp;gt; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...additionally, if you need to test for more than 1 hyphen:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; pos1 = txt.find('-')
&amp;gt;&amp;gt;&amp;gt; if txt.find('-', pos1 + 1):
 print 'wait a min, you have a 2nd hyphen!'

 
wait a min, you have a 2nd hyphen!
&amp;gt;&amp;gt;&amp;gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:11:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230143#M17840</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T11:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230144#M17841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def updateMessages(self, parameters):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; import re
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phonenumber_format = re.compile("\d{3}-\d{3}-\d{4}")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone = parameters[12]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Phone.value:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; not phonenumber_format.match(Phone.value):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is close to what I was thinking, but \d will allow for ANY digit character, and many exist outside of [0-9].&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The above will make sure you are getting XXX-XXX-XXXX where X is a digit, but if someone puts in an Eastern Arabic decimal, it too will be allowed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should create a list of values and check against them to make sure only wanted digits are used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then use both the list and Jason's response for best results.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:11:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230144#M17841</guid>
      <dc:creator>ChristopherBlinn1</dc:creator>
      <dc:date>2021-12-11T11:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230145#M17842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No, &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;\d&lt;/SPAN&gt;&lt;SPAN&gt; requires the &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;re.U&lt;/SPAN&gt;&lt;SPAN&gt; flag to match anything outside of &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;0-9&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;A href="http://docs.python.org/2.7/library/re.html"&gt;per the documentation&lt;/A&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&lt;/SPAN&gt;&lt;STRONG style="font-family: Courier New;"&gt;\d&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]When the UNICODE flag is not specified, matches any decimal digit; this is equivalent to the set [0-9]. With UNICODE, it will match whatever is classified as a decimal digit in the Unicode character properties database.[/INDENT][/INDENT]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Aug 2013 15:26:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230145#M17842</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-08-06T15:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230146#M17843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;No, &lt;SPAN style="font-family:Courier New;"&gt;\d&lt;/SPAN&gt; requires the &lt;SPAN style="font-family:Courier New;"&gt;re.U&lt;/SPAN&gt; flag to match anything outside of &lt;SPAN style="font-family:Courier New;"&gt;0-9&lt;/SPAN&gt;, &lt;A href="http://docs.python.org/2.7/library/re.html"&gt;per the documentation&lt;/A&gt;:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;[INDENT]&lt;STRONG style="font-family: Courier New;"&gt;\d&lt;/STRONG&gt;&lt;BR /&gt;[INDENT]When the UNICODE flag is not specified, matches any decimal digit; this is equivalent to the set [0-9]. With UNICODE, it will match whatever is classified as a decimal digit in the Unicode character properties database.[/INDENT][/INDENT]&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looks like we all learned something today.&amp;nbsp; Thanks for the clarification.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Aug 2013 15:31:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230146#M17843</guid>
      <dc:creator>ChristopherBlinn1</dc:creator>
      <dc:date>2013-08-06T15:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230147#M17844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't know, to be safe you may want to use an explicit list/dict, but this statement from the python docs may help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;\d&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When the UNICODE flag is not specified, matches any decimal digit; this is equivalent to the set [0-9]. With UNICODE, it will match whatever is classified as a digit in the Unicode character properties database.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, the syntax to expand the def to allow Unicode characters is to use a 'flag' param (optional parameter) as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; re.compile("\d{3}-\d{3}-d{4}", flags=re.UNICODE)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...but if I'm not mistaken, ASCII is the default?&amp;nbsp;&amp;nbsp; I'm not 100% but wouldn't that remove from consideration, say, an Eastern Arabic decimal?&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2.6/library/re.html?#re.compile"&gt;http://docs.python.org/2.6/library/re.html?#re.compile&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/2.6/library/re.html?#re.UNICODE"&gt;http://docs.python.org/2.6/library/re.html?#re.UNICODE&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps - I have little experience with the 'regular expressions' re module, very interesting.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Haha, great stuff -- looks like while my head was spinning and forming my response, the guys have already responded.&amp;nbsp; Way to go, Jason and Christopher!&amp;nbsp; Thanks for this - I've been struggling dealing with Unicode with something else I've been tinkering with, perhaps a use for re - but for now I've gotten around it with importing codecs and opening a problematic txt file with encoding='utf-16-le'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...after deleting my previous post, I probably wouldn't have given this a 2nd look, but thanks to Christopher questioning what exactly \d specifies, I agree wholeheartedly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"Looks like we all learned something today."&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Aug 2013 15:44:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230147#M17844</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-08-06T15:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230148#M17845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you so much Jason, this worked for me. I've just added "if" to the second if statement and it worked wonders!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you Wayne and Christoper for your comments also! I've never heard of the re module so this will be very helpful for expressions in the future!!!:cool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import re
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; phonenumber_format = re.compile("\d{3}-\d{3}-\d{4}")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Phone.value:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not phonenumber_format.match(Phone.value):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Phone.setErrorMessage("Make sure the phone number is in this format: ex: 979-458-6630")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:11:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230148#M17845</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2021-12-11T11:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230149#M17846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A snippet from Mark Pilgrim's "Dive into Python", chapter 7 about the re module..&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;Regular expressions are extremely powerful, but they are not the correct solution for every problem. You should learn&lt;BR /&gt;enough about them to know when they are appropriate, when they will solve your problems, and when they will cause&lt;BR /&gt;more problems than they solve.&lt;BR /&gt;Some people, when confronted with a problem, think "I know, I'll use regular expressions."&lt;BR /&gt;Now they have two problems.&lt;BR /&gt;�??�??Jamie Zawinski, in comp.emacs.xemacs&lt;BR /&gt;(&lt;A href="http://groups.google.com/groups?selm=33F0C496.370D7C45%40netscape.com"&gt;http://groups.google.com/groups?selm=33F0C496.370D7C45%40netscape.com&lt;/A&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All the stuff about parsing phone numbers etc is in there. But re expressions just give me a headache...!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But well done for the answer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 05:57:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230149#M17846</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2013-08-07T05:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can I check if a string has numbers (0-9) and dashes?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230150#M17847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I agree Neil, expressions are a solution but also another problem! It is like opening a can of worms &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Aug 2013 20:27:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-check-if-a-string-has-numbers-0-9-and/m-p/230150#M17847</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-08-12T20:27:24Z</dc:date>
    </item>
  </channel>
</rss>

