Form validation using jQuery Poppa Plugin
Last Updated :
22 Jul, 2024
In this article, we will learn how to implement form validation using jQuery Poppa plugin. It is a very easy to use, reliable, cross-browser friendly, and lightweight plugin that makes client-side validation very simple.
Note: Please download the jQuery Poppa plugin in the working folder and include the required files in the head section of your HTML code.
<link href=”https://fonts.googleapis.com/css?family=Roboto:300,400,700”
rel=”stylesheet” type=”text/css”/>
<link href=”https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css”
rel=”stylesheet” type=”text/css”/>
<link href=”https://use.fontawesome.com/releases/v5.5.0/css/all.css”
rel=”stylesheet” type=”text/css”/>
<link href=”validation.css?family=Roboto:300,400,700”
rel=”stylesheet” type=”text/css”/>
<link href=”global.css?family=Roboto:300,400,700”
rel=”stylesheet” type=”text/css”/>
<link href=”github.css?family=Roboto:300,400,700”
rel=”stylesheet” type=”text/css”/>
<script src=”global.js”></script>
<script src=”poppa.js”></script>
<script src=”highlight.js”></script>
Example 1: The following example demonstrates simple form validation using jQuery Poppa plugin. The output shows the validation in action when given invalid inputs.
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width, initial-scale=1">
<title>jQuery form validation Poppa plugin</title>
<link rel="stylesheet"
href=
"https://fonts.googleapis.com/css?family=Roboto:300,400,700">
<!-- Include Bootstrap CSS -->
<link rel="stylesheet"
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<!-- Include FontAwesome CSS -->
<link rel="stylesheet"
href=
"https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<!-- Include the Poppa Plugin Stylesheets -->
<link rel="stylesheet" type="text/css"
href="validation.css">
<link rel="stylesheet" type="text/css"
href="global.css">
<link rel="stylesheet" type="text/css"
href="github.css">
<style>
h2 {
padding-left: 300px;
}
</style>
</head>
<body>
<h2 style="color:green">
GeeksforGeeks
</h2>
<b style="padding-left:300px">
jQuery form validation Poppa
plugin
</b>
<br><br>
<div class="container">
<div class="row">
<div class="col-9">
<div class="example-block mb-4">
<form action="" class="user-registration mb-3">
<h6 class="title mb-2 mt-0">
Registration form for User
</h6>
<div class="form-group">
<label>Login ID</label>
<input name="login" type="text"
data-validation-length="min:3"
class="form-control" required>
</div>
<div class="form-group">
<label>Email ID</label>
<input name="email" type="email"
class="form-control" required>
</div>
<div class="form-group">
<label>Password</label>
<input name="password" type="password"
class="form-control" required>
</div>
<div class="form-group">
<label>Website</label>
<input name="website" data-validation-type="url"
class="form-control">
</div>
<div class="form-group">
<label class="mb-0">
I agree to the terms of service
</label>
<input type="checkbox"
data-validation-message=
"You have to agree to terms of service"
required>
</div>
<button type="submit" class="btn btn-primary">
Submit
</button>
</form>
</div>
</div>
</div>
</div>
<!-- Include jQuery -->
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<!-- Include the Poppa Plugin Scripts -->
<script src="global.js"></script>
<script src="poppa.js"></script>
<script src="highlight.js"></script>
<script>
$(document).ready(function () {
/** Initiate highlighting */
hljs.initHighlightingOnLoad();
/** Initiate validation on each form */
$('.user-registration').validation({
'autocomplete': 'off',
'liveValidation': false
});
});
</script>
</body>
</html>
Output:
Example 2: The following example demonstrates the above example with active live validation with some minor custom changes. When live validation is enabled, it allows each input to be validated immediately. This happens when the user types into the input or when it loses focus.
html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width,
initial-scale=1">
<title>jQuery form validation Poppa plugin</title>
<link rel="stylesheet"
href=
"https://fonts.googleapis.com/css?family=Roboto:300,400,700">
<!-- Include Bootstrap CSS -->
<link rel="stylesheet"
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<!-- Include FontAwesome CSS -->
<link rel="stylesheet"
href=
"https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<!-- Include the Poppa Plugin Stylesheets -->
<link rel="stylesheet" type="text/css" href="validation.css">
<link rel="stylesheet" type="text/css" href="global.css">
<link rel="stylesheet" type="text/css" href="github.css">
<style>
h2 {
padding-left: 300px;
}
</style>
</head>
<body>
<h2 style="color:green">
GeeksforGeeks
</h2>
<b style="padding-left:300px">
jQuery form validation Poppa plugin
</b>
<p></p>
<div class="container">
<div class="row">
<div class="col-9">
<div class="example-block mb-4">
<form action="" class="live-validation mb-3"
id="live-validation">
<div class="form-group">
<label>Login ID</label>
<!-- Validation for Upper case only-->
<input name="login" type="text"
data-validation-regexp="^[A-Z]+$"
class="form-control" required>
</div>
<div class="form-group">
<label>Salary</label>
<!-- Validation for type number
with min and max values-->
<input name="login" type="number"
min="10000" max="30000"
class="form-control" required>
</div>
<div class="form-group">
<label>Email ID</label>
<input name="email" type="email"
class="form-control" required>
</div>
<div class="form-group">
<label>Password</label>
<input name="password"
data-validation-type="alphanumeric"
type="password" class="form-control"
required>
</div>
<div class="form-group">
<label>Website</label>
<!-- Valid url patterns include
www.sitename.com or
https://www.sitename.com -->
<input name="website"
data-validation-type="url"
class="form-control">
</div>
<div class="form-group">
<label>Describe yourself</label>
<textarea name="bio"
data-validation-length="min:10,max:150"
data-validation-hint="Write your biodata"
data-validation-hint="Describe about yourself"
class="form-control">
</textarea>
</div>
<div class="form-group">
<label class="mb-0">
I agree to the terms of service
</label>
<!-- Custom validation message -->
<input type="checkbox"
data-validation-rqmessage=
"Please agree to terms of service"
required>
</div>
<button type="submit" class="btn btn-primary">
Submit Form
</button>
</form>
</div>
</div>
</div>
</div>
<!-- Include jQuery -->
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
<!-- Include the Poppa Plugin Scripts -->
<script src="global.js"></script>
<script src="poppa.js"></script>
<script src="highlight.js"></script>
<script>
$(document).ready(function () {
/* Initiate highlighting */
hljs.initHighlightingOnLoad();
/* Initiate live validation on each form */
$('.live-validation').validation({
'autocomplete': 'on',
'liveValidation': true
});
});
</script>
</body>
</html>
Output:
Similar Reads
jQuery Page Piling Plugin jQuery pagePiling.js plug-in is a rich feature available for programmers for piling more than one layout section, one over the other, and accessing each page by URL or mouse scrolling or side bullets navigation. This feature provides all type of smooth vertical, horizontal, and side navigations to t
5 min read
jQuery | Flickerplate Plugin jQuery provides Flickerplate plugin that helps our programmers to create sliders for websites that can cycle through a list of background images along with dot navigation feature and animated arrows. The plugin consists of many more libraries that are responsible for touch detections and events such
5 min read
jQuery Multiscroll Plugin jQuery provides multiscroll.js plugin which helps programmers to create split web pages along with divided multiple vertical scrolling panels.Note: Please download the jQuery multiscroll plugin to your working folder and include the required files in the head section of your code as shown below. Dow
3 min read
jQuery RowGrid Plugin jQuery provides a very simple, user-friendly and responsive rowGrid plugin that helps programmers to display images in a straight row. It is very lightweighted and supports infinite scrolling feature. Real examples of rowGrid are Google+ images or Google image search that appears in a straight row g
4 min read
jQuery Alertify Plugin jQuery framework provides alertify.js plugin that provides pre-designed customizable notification system along with interactive browser dialogs. This extensible and themeable plugin is very useful for developers providing an optimized version of alert messages with stacking up to feature. This small
5 min read
jQuery Image ProgressBars Plugin In this article, we will learn how to implement image ProgressBar feature using the jQuery Image ProgressBar plugin. Note: Please download the jQuery Image ProgressBar plugin in the working folder and include the required files in the head section of your HTML code. <link href=âprogressbar.cssâ r
2 min read
jQuery DrawSVG Plugin SVG or Scalar Vector Graphics is Extended Markup Language-based graphics supporting 2 dimensional animations of images enhancing interactiveness. The specifications of SVG are open standards by World Wide Web Consortium defined in XML text files. These files can be changed or created with any drawin
4 min read
jQuery Tagsort Plugin jQuery provides Tagsort plugin that is used for displaying tags or filter elements based on different tags in a DOM. The plugin takes data-attributes of HTML page structure and dynamically creates user-friendly tags used for filtering elements. The filtration of elements are done in many ways that a
9 min read
jQuery Logos Distort Plugin The jQuery provides LogosDistort plugin which helps in creating or animating a parallax environment for 3D scenes in the user browser. It uses full-page matrix3D perspective logos distortions for transforming base on mouse movement. You have to download the required files in the working folder so th
4 min read
jQuery Filer Plugin jQuery provides a quick jQuery Filer uploader plugin for easy implementation of uploading the files. It provides features like instant uploading of files, file append, file removal, multiple selections, drag and drop support along with other file validations.Download the required files to include it
2 min read