jeplowman23
Follower Insights Pro
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
In this tutorial we will create a User Password Validator using JavaScript. This code will automatically validate the password input when user enter some value in the textbox. The code itself use onkeyup() to call a function that will validate the password if it is acceptable to be use in any terms This code is free to use, you can modify it as your own,
We will be using JavaScript as a server-side scripting language because It allows greater control of your web page behavior than HTML alone. It is embedded in HTML that responsible to allow user to interact with the computer .
Getting started:
First you have to download bootstrap framework, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.
The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
Creating the Script
This code contains the script of the application. This code will automatically validate the form inputs when the inputs is entered. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.
There you have it we successfully created a User Password Validator using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
We will be using JavaScript as a server-side scripting language because It allows greater control of your web page behavior than HTML alone. It is embedded in HTML that responsible to allow user to interact with the computer .
Getting started:
First you have to download bootstrap framework, this is the link for the bootstrap that I used for the layout design https://getbootstrap.com/.
The Main Interface
This code contains the interface of the application. To create this just write these block of code inside the text editor and save this as index.html.
- <!DOCTYPE html>
- <html
lang
=
"en"
>
- <head
>
- <meta
charset
=
"UTF-8"
name
=
"viewport"
content
=
"width=device-width, initial-scale=1"
/
>
- <link
rel
=
"stylesheet"
type
=
"text/css"
href
=
"css/bootstrap.css"
/
>
- </
head
>
- <body
>
- <nav class
=
"navbar navbar-default"
>
- <div
class
=
"container-fluid"
>
- <a
class
=
"navbar-brand"
href
=
"https://sourcecodester.com"
>
Sourcecodester</
a
>
- </
div
>
- </
nav>
- <div
class
=
"col-md-3"
></
div
>
- <div
class
=
"col-md-6 well"
>
- <h3
class
=
"text-primary"
>
JavaScript - User Password Validator</
h3
>
- <hr
style
=
"border-top:1px dotted #ccc;"
/
>
- <div
class
=
"col-md-5"
>
- <form
>
- <div
class
=
"form-group"
>
- <label
>
Enter a password</
label
>
- <input
type
=
"password"
onkeyup
=
"CheckPassword(this);"
class
=
"form-control"
/
>
- </
div
>
- <span
id
=
"chk_capital"
class
=
"alert-danger"
>
X One capital in first letter</
span
>
- <br
/
>
- <span
id
=
"chk_number"
class
=
"alert-danger"
>
X Have a number digit</
span
>
- <br
/
>
- <br
/
>
- <center
><button
type
=
"button"
id
=
"btn_check"
class
=
"btn btn-primary"
disabled
=
"disabled"
>
Check</
button
></
center
>
- </
form
>
- </
div
>
- </
div
>
- </
body
>
- <script
src
=
"js/script.js"
></
script
>
- </
html
>
Creating the Script
This code contains the script of the application. This code will automatically validate the form inputs when the inputs is entered. To do this just copy and write these block of codes inside the text editor, then save it as script.js inside the js folder.
- function
CheckPassword(
password)
{
- var
chk_capital =
document.getElementById
(
'chk_capital'
)
;
- var
chk_number =
document.getElementById
(
'chk_number'
)
;
- var
bool_capital;
- var
bool_number;
- if
(
password.value
.search
(
/[0-9]/
)
>
0
)
{
- chk_number.removeAttribute
(
'class'
)
;
- chk_number.setAttribute
(
'class'
,
'alert-success'
)
;
- chk_number.innerHTML
=
"✔ Validated"
;
- bool_number =
true
;
- }
else
{
- chk_number.removeAttribute
(
'class'
)
;
- chk_number.setAttribute
(
'class'
,
'alert-danger'
)
;
- chk_number.innerHTML
=
"X Have a number digit"
;
- bool_number =
false
;
- }
- if
(
password.value
.match
(
/[A-Z]/
)
)
{
- chk_capital.removeAttribute
(
'class'
)
;
- chk_capital.setAttribute
(
'class'
,
'alert-success'
)
;
- chk_capital.innerHTML
=
"✔ Validated"
;
- bool_capital =
true
;
- }
else
{
- chk_capital.removeAttribute
(
'class'
)
;
- chk_capital.setAttribute
(
'class'
,
'alert-danger'
)
;
- chk_capital.innerHTML
=
"X One capital in first letter"
;
- bool_capital =
false
;
- }
- if
(
bool_capital &&
bool_number)
{
- document.getElementById
(
'btn_check'
)
.removeAttribute
(
'disabled'
)
;
- }
else
{
- document.getElementById
(
'btn_check'
)
.setAttribute
(
'disabled'
,
'disabled'
)
;
- }
- }
There you have it we successfully created a User Password Validator using JavaScript. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
You must upgrade your account or reply in the thread to view hidden text.