Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Name Of Student: Varada K.

Datar Roll No: 45013


Division: A Exam Seat No: B150318644

Assignment 2
Title: JQuery
Problem Statement: Design an online registration form for any application and validate it
using JQuery.
Pre-requisites:
Experimental setup: Windows 10 OS, Visual Studio Code

Date of Completion: 17/05/2021


Assessment Grade / Marks:
Assessor’s Sign with Date:

Theory:
• jQuery- It is a fast, small, and feature-rich JavaScript library. It makes things like HTML
document traversal and manipulation, event handling, animation, and Ajax much simpler
with an easy-to-use API that works across a multitude of browsers. With a combination of
versatility and extensibility, jQuery has changed the way that millions of people write
JavaScript.
• form validations ((e.g. Email, mobile, Pin code, Password)) –
Form validation is a process of confirming the relevant information entered by the user in the
input field. Here we will be validating a simple form that consists of a username, password
and a confirm password using jQuery.
• Validate URL - Given a URL as a character string str of size N.The task is to check if the
given URL is valid or not.
1. Get the URL.
2. Create a regular expression to check the valid URL
3. The URL must start with either http or https and
4. then followed by :// and
5. then it must contain www. And then followed by subdomain of length (2, 256) and
last part contains top level domain like .com, .org etc.
6. Match the given URL with the regular expression. In Java, this can be done by using
Pattern.matcher().
7. Return true if the URL matches with the given regular expression, else return false
• Functions empty - The empty() function checks whether a variable is empty or not. This
function returns false if the variable exists and is not empty, otherwise it returns true.
• Preg match - preg_match — Perform a regular expression match. preg_match() returns 1 if
the pattern matches given subject, 0 if it does not, or false if an error occurred.
1. Pattern - The pattern to search for, as a string.
2. Subject - The input string.
3. Matches - If matches is provided, then it is filled with the results of search.
$matches[0] will contain the text that matched the full pattern, $matches[1] will have
the text that matched the first captured parenthesized subpattern, and so on.

4. Flags - flags can be a combination of the following flags:


▪ PREG_OFFSET_CAPTURE - If this flag is passed, for every occurring
match the appendant string offset (in bytes) will also be returned.
▪ PREG_UNMATCHED_AS_NULL - If this flag is passed, unmatched
subpatterns are reported as null; otherwise they are reported as an empty
string.
▪ Offset - Normally, the search starts from the beginning of the subject string.
The optional parameter offset can be used to specify the alternate place from
which to start the search (in bytes).

• Filter var in PHP- The filter_var() function filters a variable with the specified filter.
Returns the filtered data on success, FALSE on failure
o Syntax
filter_var(var, filtername, options)
o Var - Required. The variable to filter
o Filtername-Optional. Specifies the ID or name of the filter to use. Default is
FILTER_DEFAULT, which results in no filtering
o Options-Optional. Specifies one or more flags/options to use. Check each filter
for possible options and flags

Input:
$(function() {

$("form[name='registration']").validate({

rules: {

fullname: "required",
username: "required",
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
}
},
messages: {
firstname: "Please enter your fullname",
lastname: "Please enter your username",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5
characters long"
},
email: "Please enter a valid email address"
},
submitHandler: function(form) {
form.submit();
}
});
});

Output:

Conclusion: Thus we implemented form validations in JQuery with the help of PHP.

You might also like