Check if an string has an integer in an if condition
<pre><code>file = open('Name.txt', 'r')
name =  str(file.read())
file.close()
</code></pre>

<p>In the file called 'Name.txt', the user will input a name. The program is to check whether or not the name is valid.</p>

<p>E.g:</p>

<p>1bob - is not valid</p>

<p>bob - is valid</p>

<p>Is it possible to do this with an if condition? </p>

<p>You could use regular expression : </p>

<p>i.e : </p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; regex = re.compile(r'.*[0-9]')
&gt;&gt;&gt; names = ['Bob', 'John', '1Bob', 'John2']
&gt;&gt;&gt; for name in names: 
...     if not regex.match(name):
...          print name
... 
Bob
John
</code></pre>

<p><code>.*</code> matches any character (except newline) </p>

<p>Quantifier: <code>*</code> Between zero and unlimited times</p>

<p><code>[0-9]</code> match a single character present in the list below</p>

<p><code>0-9</code> a single character in the range between 0 and 9</p>

<p>Hope it helps.</p>

python