ProjectBatch11AM 11012021
ProjectBatch11AM 11012021
Example Pattern:
Email Pattern : ___ @___.__
PanCard Pattern: AAAA8888L
..etc
+ - min 1, max -n
* - min 0, max -n (n-no limit)
? - min 0, max -1
None - min-1, max-1
Inputs:
SAM (invaild) -- Min size not reached
ajaymn (invaild) -- only Uppercase chars
AB12CD (invaild) -- Numbers are not allowed
2.
[0-9]{2,6}
=> Inside Text input, we can enter only
digits only. Min-2 digits and max-6. digits
Inputs:
6565 (Valid)
abcd (invalid) Only Digits allowed
3. [a-z]+
Allowed chars are lower case a-z
and at least one char, at most n chars
min-1, max-no limit
Input:
sample (valid)
123 (invalid)
Input:
Y (valid)
N (valid)
q (invalid) only Uppercase
5. [A-Z][a-z]
For first box 1 char
For 2nd box 1 char
Exactly 2 chars, First one Uppercase
and 2nd must be lowercase
Input:
Jai (Invalid) Size 2 chars only
Hi (Valid)
6. [a-z]?
Allowd chars a-z only. Min-zero and max- one
Input
(Entered Nothing) (Valid)
m (valid)
T (invalid)
7. [A-Z]*
Allowed only Uppercase Min-zero, max-n no limit
Input:
DATA (VALID)
(No Input) (Valid)
SAM SUNG (INVALID) Space is not allowed
Input:
A2aws (Valid)
989898axe (Valid)
404not (Valid)
Rat86 (Invalid) -After uppercase, next thing must be digits
and must end with 3 chars
9. [a-zA-Z0-9]{3,5}
=> We can enter any of lower,upper chars and digits in
any order. Must be 3-5 chars only.
No need to have all chars in order.
Input:
Som23 (Valid)
ajay (Valid)
9999 (Valid)
SAMAB (Valid)
10. [a-z][A-Z][0-9]
1 cha + 1 char + 1 digit = 3 char (min/max)
Order must be followed.
Input:
aA2 (Valid)
A9y (Invalid) -- Order must be followed
abZY99 (Invalid) -- Size min/max-3 only
11.
[a-zA-Z]?[A-Z0-9]+[a-z0-9]*
Inputs:
AJAY (Valid)
gOOgle (Valid)
hAPPy2021 (Valid)
-------------------------------------------------
JQuery Validation Steps
--HTML/Body--
Define one row
-> col-3 Label
-> col-4 Form Input
-> col-5 Span(erro) section
--Script--
1. hide Error section
2. define error variable
3. function- validate
4. link with event
-----------------------------------------
Form Submit:-
When we click on form submit, we should validate
all Inputs, If their error variables are
returning true then Submit Form(return true).
If any one error variable is false. Then do not
submit form (return false).
--code modifications---
1. At Form tag level - add id
$("#stdForm").submit(function () {
//call all validate function
//if (errorVariable) all truen return true
else false;
});
---Example--------
<html>
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="container">
<h3>Student Register Form</h3>
<form id="stdForm" action="#" method="POST">
<div class="row">
<div class="col-3">
<label>NAME</label>
</div>
<div class="col-4">
<input type="text" name="stdName" id="stdName" class="form-
control" />
</div>
<div class="col-5">
<span id="stdNameError"></span>
</div>
</div>
<input type="submit" value="Add" class="btn btn-success"/>
</form>
</div>
<script type="text/javascript">
$(document).ready(function () {
//1. hide error section
$("#stdNameError").hide();
return stdNameError;
}
//5. on submit
$("#stdForm").submit(function () {
//call all validate functions
validate_stdName();
if (stdNameError) {
return true; //submit form to server
} else {
return false; //do not submit
}
});
});
</script>
</body>
</html>
------------------------------------------
Task:
1. Employee name: only accept a-z/A-Z (min-5,max-12)