RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Regular expression to validate credit card number

Credit card numbers contain four groups of numbers where each group contains 4 numbers. The following regular expression ( regexp ) will accept all credit card number in this format: - 1234 5678 1234 5678 - 1234567812345678 - 1234-5678-1234-5678

#!/bin/bash

# regexp to get a valid credit card number

echo $1 | grep -qE '^([0-9]{4}[- ]?){3}[0-9]{4}$' 

if [ $? -eq 0 ]; then
	echo "$1 is a valid credit card number."
else
	echo "$1 is an invalid credit card number."
fi

Execution:

$ chmod +x validate_credit_card_number.sh

$ ./validate_credit_card_number.sh "1234 5678 1234 5678"
1234 5678 1234 5678 is a valid credit card number.

$ ./validate_credit_card_number.sh 1234567812345678
1234567812345678 is a valid credit card number.

$ ./validate_credit_card_number.sh 1234-5678-1234-5678
1234-5678-1234-5678 is a valid credit card number.

$ ./validate_credit_card_number.sh 1234-5678-1234-56786
1234-5678-1234-56786 is an invalid credit card number.

$ ./validate_credit_card_number.sh 1234-55678-1234-5678
1234-55678-1234-5678 is an invalid credit card number.

Share this linux post:

Submit Regular expression to validate credit card number in Delicious Submit Regular expression to validate credit card number in Digg Submit Regular expression to validate credit card number in FaceBook Submit Regular expression to validate credit card number in Google Bookmarks Submit Regular expression to validate credit card number in Stumbleupon Submit Regular expression to validate credit card number in Technorati Submit Regular expression to validate credit card number in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download