1 of 7

Web Technologies

Java Script Validations

Smt M.Jeevana Sujitha

Assistant Professor

Department of Computer Science and Engineering

SRKR Engineering College, Bhimavaram, A.P. - 534204

2 of 7

OBJECTIVES

The Objectives of this lecture are

  • To learn about how to validate an html form.

3 of 7

Java Script Validations

  • RegExp: A regular expression is an object that describes a pattern of characters.
  • Regular expressions are used

powerful pattern matching and

to perform search-and-

replace functions on text.

  • Syntax:

var patt=/pattern/modifiers;

  • Where pattern specifies the pattern of an expression.
  • Modifiers specify if a search should be global, case sensitive…

4 of 7

Java Script Validations

Character

Description

$

Matches end of string line

/…./

All regular expressions start and end with

forward slashes

^

Matches the beginning of the string or

line

\w+ or [A-Z a-z 0-9 _]

Matches one or more characters including

the underscore

?

Matches the previous character zero or 1

time

*

Matches the previous character 0 or more

times

@

It matches only @ character

\.\w{2,3}

It matches a “.” Followed by 2 or 3

characters. Ex: .edu

5 of 7

Java Script Validations

Character

Description

+

This sign specifies above sub expression

occurs one or more times

6 of 7

Example:

var email=/^[a-z A-Z 0-9 . _ -]+@[a-z A-Z

.]+\.[a-z A-Z] {2,4}$/

var phone=/^\d{10}$/;

Java Script Validations

7 of 7

THANK YOU