[BangPypers] Fwd: How to validate a String with spaces using inbuilt validate function

Anand Balachandran Pillai abpillai at gmail.com
Tue Sep 15 09:30:39 CEST 2009

On Tue, Sep 15, 2009 at 11:38 AM, Sampath Girish
<girishmsampath at gmail.com>wrote:

> Hi all,        Can anyone please tell me how to validate a String with
> spaces provided in between using inbuilt validate function. Please give me a
> solution for this.

Did not understand what you meant by inbuilt validate function. There is
nothing like that in Python.

>>> s='Python'
>>> s.validate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'validate'
>>> validate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'validate' is not defined

> For e.g., Name: *Python**_**India.* The '_ ' is the space. When i use
> 'validate' function in entry field, it must be able to detect spaces and
> text only and accept that.

 Use a regular expression. For example, the following does the job for
 matching a string with space in between 2 words.
>>> import re
>>> r=re.compile(r'\w+\s+\w+', re.IGNORECASE|re.LOCALE)
>>> r.match('PythonIndia')
>>> r.match('Python India')
<_sre.SRE_Match object at 0x7f0d17909168

> Thanks in advance,
> Sampath Girish M
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20090915/3e213cdc/attachment-0001.htm>

More information about the BangPypers mailing list