Table of contents
1.
Introduction💁
2.
Text Format Validators ✔️
2.1.
IS_ALPHANUMERIC
2.1.1.
Controller File
2.1.2.
View File
2.1.3.
Output
2.2.
IS_LOWER, IS_UPPER
2.3.
IS_EMAIL
2.3.1.
Controller File
2.3.2.
View File
2.3.3.
Output
2.4.
IS_MATCH
2.4.1.
Controller File
2.4.2.
View File
2.4.3.
Output
2.5.
IS_LENGTH
2.5.1.
Controller File
2.5.2.
View File
2.5.3.
Output
2.6.
IS_URL
2.6.1.
Controller File
2.6.2.
View File
2.6.3.
Output
3.
Frequently Asked Questions
3.1.
What is web2py?
3.2.
What is Text Format Validator?
3.3.
What is Python?
3.4.
How to install web2py?
3.5.
What is the default port in web2py?
4.
Conclusion
Last Updated: Aug 13, 2025
Medium

Text Format Validators

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction💁

Before we dive into Text Validators Functions, we need to understand web2py. So what is web2py? Web2py is an open-source web application framework that is written in the Python programming language. It is used to create dynamic web pages using Python. It cuts down a lot of tedious hard work of creating a webpage, such as creating a form from scratch. 

Text Format Validators ✔️

Now that we know a little bit about web2py, we can talk about Text Format Validators. So Text Format Validators are certain functions in the web2py package that are used to validate a text field against some given condition. Let us look at a few different types of Text Format Validators present in web2py.

IS_ALPHANUMERIC

This Text Format Validator is used to validate that the text in the text field does not contain any special symbols.

validate = IS_ALPHANUMERIC(error_message='Please Enter an alphanumeric value!!')
You can also try this code with Online Python Compiler
Run Code

 

The above line of code is used to validate the text using the IS_ALPHANUMERIC function.
 

Lets us look at an example,

Controller File

def user():
    form=FORM('Your name:',
              INPUT(_name='name', requires=IS_ALPHANUMERIC(error_message="Please Enter an alphanumeric value!!")),
              INPUT(_type='submit'))
    if form.accepts(request, session):
        response.flash = 'form accepted'
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
You can also try this code with Online Python Compiler
Run Code

 

View File

{{extend 'layout.html'}}
<h2>Input form</h2>
{{=form}}
<h2>Submitted variables</h2>
{{=BEAUTIFY(request.vars)}}
<br><br>
<h2>Errors in form</h2>
{{=BEAUTIFY(form.errors)}}

 

Output

Output 1 for IS_ALPHANUMERIC
Output 2 for IS_ALPHANUMERIC

IS_LOWER, IS_UPPER

These Text Format Validators do not return an error. Rather they convert the text to lower or upper case, respectively. We can use the following code snippets to implement these functions,

requires = IS_LOWER()

requires = IS_UPPER()

IS_EMAIL

This Text Format Validator is used to validate that the text in the text field is a valid email id.

 validate = IS_ALPHANUMERIC(error_message='Please Enter a valid Email!!')
You can also try this code with Online Python Compiler
Run Code

 

The above line of code is used to validate the text using the IS_LOWER function.

 

Lets us look at an example,

Controller File

def user():
    form=FORM('Your name:',
              INPUT(_name='name', requires=IS_ALPHANUMERIC(error_message="Please Enter an alphanumeric value!!")),
              INPUT(_type='submit'))
    if form.accepts(request, session):
        response.flash = 'form accepted'
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
You can also try this code with Online Python Compiler
Run Code

 

View File

{{extend 'layout.html'}}
<h2>Input form</h2>
{{=form}}
<h2>Submitted variables</h2>
{{=BEAUTIFY(request.vars)}}
<br><br>
<h2>Errors in form</h2>
{{=BEAUTIFY(form.errors)}}

 

Output

Output 1 for IS_EMAIL
Output 2 for IS_EMAIL

IS_MATCH

This Text Format Validator is used to match against a given regular expression, and if the text does not match, it returns an error message.

require = IS_MATCH(error_message='Please Enter a valid IP!!')
You can also try this code with Online Python Compiler
Run Code

 

The above line of code is used to validate the text using the IS_MATCH function.
 

Lets us look at an example,

Controller File

def user():
form=FORM('IP Add:',
              INPUT(_name='name', requires=IS_MATCH('^\d{1,3}(.\d{1,3}){3}$',
         error_message='Please enter a valid IP')),
              INPUT(_type='submit'))
    if form.accepts(request, session):
        response.flash = 'form accepted'
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
You can also try this code with Online Python Compiler
Run Code

 

View File

{{extend 'layout.html'}}
<h2>Input form</h2>
{{=form}}
<h2>Submitted variables</h2>
{{=BEAUTIFY(request.vars)}}
<br><br>
<h2>Errors in form</h2>
{{=BEAUTIFY(form.errors)}}

 

Output

Output 1 for IS_MATCH
Output 2 for IS_MATCH

IS_LENGTH

This Text Format Validator is used to check whether the length of the given text fits within the set boundaries.

require = IS_LENGTH(minsize=8, error_message='Password should be atleast 8 characters long!!')
You can also try this code with Online Python Compiler
Run Code

 

The above line of code is used to validate the text using the IS_LENGTH function.
 

Lets us look at an example,

Controller File

def user():
form=FORM('Pass:',
              INPUT(_name='name', require = IS_LENGTH(minsize=8, error_message='Password should be atleast 8 characters long!!')
),
              INPUT(_type='submit'))
    if form.accepts(request, session):
        response.flash = 'form accepted'
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
You can also try this code with Online Python Compiler
Run Code

 

View File

{{extend 'layout.html'}}
<h2>Input form</h2>
{{=form}}
<h2>Submitted variables</h2>
{{=BEAUTIFY(request.vars)}}
<br><br>
<h2>Errors in form</h2>
{{=BEAUTIFY(form.errors)}}

 

Output

Output 1 for IS_LENGTH
Output 2 for IS_LENGTH

IS_URL

This Text Format Validator is used to check whether the given text is a URL or not.

require = IS_URL(error_message='Please enter a valid URL!!')
You can also try this code with Online Python Compiler
Run Code

 

The above line of code is used to validate the text using the IS_URL function.

 

Lets us look at an example,

Controller File

def user():
form=FORM('URL:',
              INPUT(_name='name', requires = IS_URL(mode='generic',
                  allowed_schemes=['ftps', 'https'],
                  prepend_scheme='https', error_message='Please enter a valid URL!!')),
              INPUT(_type='submit'))
    if form.accepts(request, session):
        response.flash = 'form accepted'
    elif form.errors:
        response.flash = 'form has errors'
    else:
        response.flash = 'please fill the form'
    return dict(form=form)
You can also try this code with Online Python Compiler
Run Code

 

View File

{{extend 'layout.html'}}
<h2>Input form</h2>
{{=form}}
<h2>Submitted variables</h2>
{{=BEAUTIFY(request.vars)}}
<br><br>
<h2>Errors in form</h2>
{{=BEAUTIFY(form.errors)}}

 

Output

Output 1 for IS_URL
Output 2 for IS_URL

Frequently Asked Questions

What is web2py?

Web2py is an open-source web application framework that is written in the Python programming language. It is used to create dynamic web pages using Python. It cuts down a lot of tedious hard work of creating a webpage, such as creating a form from scratch. 

What is Text Format Validator?

Text Format Validators are certain functions in the web2py package that are used to validate a text field against some given condition. It could either be validating a String, a phone number, a URL, etc.

What is Python?

Python is a general-purpose, high-level, interpreted programming language. Python emphasizes easy code readability by using a significant amount of indentation. It was released in the year 1991. 

How to install web2py?

We can install web2py from the official web2py website.

We can also use the following commands to install web2py

  • UNIX and Linux: web2py.py
  • OS X open: web2py.app
  • Windows: web2py.exe

What is the default port in web2py?

The default port in web2py is set to 8000, but developers can change it at any time. Developers can also change the admin password according to their own convenience.

Conclusion

This Blog covered all the necessary points about Text format Validators in the web2py package. We also looked at the various different types of Text Format Validators. In the end, we discussed a few codes to get a better grasp of the topic. 

Hey Ninjas! Don’t stop here. Check out Coding Ninjas for Python, more unique courses, and guided paths. Also, try Coding Ninjas Studio for more exciting articles, interview experiences, and excellent Machine Learning and Python problems. 

Live masterclass