Introduction
In this article I explain card number validation in PHP using JavaScript and discuss how to validate a credit card and master cart number with a JavaScript function. You can change easily any card number format using a regular expression. I am using HTML and CSS for the card design.
Example
This CSS file is to be saved as "form.css".
li {list-style-type: none;
font-size: 16pt;
}
.sent {
margin: auto;
padding-top: 10px;
padding-bottom: 10px;
width: 400px;
background:#F9BB60;
border: 2px soild silver;
}
.sent h2 {
margin-left: 38px;
}
input {
font-size: 20pt;
}
input:focus, textarea:focus{
background-color:#99FFCC;
}
.rq {
color:#FF3366;
font-size: 10pt;
}
This is a JavaScript file for validating a credit card number; save the file as "credit-validation.js".
function credit(inputtxt)
{
//using regular expression
var number = /^(?:4[0-9]{12}(?:[0-9]{3})?)$/;
if(inputtxt.value.match(number))
{
return true;
}
else
{
alert("Not a valid Visa credit card number!");
return false;
}
}
This is a HTML file for using credit card design.
<html>
<head>
<meta charset="utf-8">
<title>Credit Card</title>
<link rel='stylesheet' href='form.css' type='text/css' />
</head><br><body onload='document.form1.text1.focus()'>
<div class="sent">
<h2>Starting with 4 length 13 or 16 digits and Submit</h2>
<form name="form1" action="#">
<ul>
<li><input type='text' name='text1'/></li>
<li> </li>







Join the conversation! Your thoughts help the community grow.