JavaScript 4. User Input Validation



Similar documents
5544 = = = Now we have to find a divisor of 693. We can try 3, and 693 = 3 231,and we keep dividing by 3 to get: 1

Anatomy of Credit card Numbers

Testing Hypotheses About Proportions


Impact of Breast Cancer Genetic Testing on Insurance Issues

Check Digits for Detecting Recording Errors in Horticultural Research: Theory and Examples

2) Based on the information in the table which choice BEST shows the answer to 1 906?

Local Property Tax 3 rd Party Cash Payment Service Providers. Local Property Tax

Irish benefits under the agreement on social security between Ireland and New Zealand

Queries Requiring Two Tables

Digital Cash. is not a check, credit card or a debit card. They leave audit trails. can be sent through computer networks.

CS177 MIDTERM 2 PRACTICE EXAM SOLUTION. Name: Student ID:

Frequently Asked Questions for Order Processing and Payment Options:

Family Law. Analytical Report

Lecture 13. Understanding Probability and Long-Term Expectations

Chapter 8. Receivables

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

IPREX Blogbarometer 2015

Enhance Luhn Algorithm for Validation of Credit Cards Numbers

Medicare enrolment application

Authorize.Net. Advanced Integration Method. Miva Merchant Module. Documentation for module version Last Updated: 5/07/03

MII stands for major industry identifier; 4 and 5 indicate Banking and Financial. VISA cards begin with 4 and MasterCard cards with 5.

Bivariate Statistics Session 2: Measuring Associations Chi-Square Test

Supported Payment Methods

Selective Service CHAPTER

Medical Card and GP Visit Card Application Form - People Aged 70 Years or Older MC1(a)

MATH 140 Lab 4: Probability and the Standard Normal Distribution

Supported Payment Methods

Microsoft Excel 2007 Cell Validation (Level 3)

Cost of Medical Care in respect of an Occupational Accident or Disease

MULTIPLE REGRESSION WITH CATEGORICAL DATA

The Mathematics of the RSA Public-Key Cryptosystem

Merchant account application form

Cash service pricing policy

Equal marriage What the government says

The Normal Distribution

Change of Registrar Instructional Information

BB&T Association Services Online Payment System Sample Screens Revised 04/16/2012

Application for a Parental Order Section 54 Human Fertilisation and Embryology Act 2008

Introduction to the Practice of Statistics Fifth Edition Moore, McCabe

Lowest Common Multiple and Highest Common Factor

Pension Life Insurance Plan for Personal Pensions

Expenditure and Outputs in the Irish Health System: A Cross Country Comparison

Guidance Notes for Life Assurance Companies

How To Increase Your Odds Of Winning Scratch-Off Lottery Tickets!

Catholic Archives Society Publications. Archive Advice Leaflet No. 10

Number Theory. Proof. Suppose otherwise. Then there would be a finite number n of primes, which we may

Microsoft Excel Tips & Tricks

Retirement instruction for company pension and buy out bond

1. The RSA algorithm In this chapter, we ll learn how the RSA algorithm works.

Chapter Objectives. Chapter 9. Sequential Search. Search Algorithms. Search Algorithms. Binary Search

Table 1: Field Experiment Dependent Variable Probability of Donation (0 to 100)

Risks Factors for Teenage Pregnancy and The Youth Perspective on Teenage Pregnancy and Health Needs in Nkalashane, Swaziland

Instructions for applying data validation(s) to data fields in Microsoft Excel

OVERVIEW SUPPORTED PAYMENT METHODS

Best Practices for Computer Programming in Economics

Crystal Clear Contract Services Limited Application Form CIS/Sole Trader

Ordering. Evergreen Acquisitions revised August 2015 Section 3-1

EXAM. Exam #3. Math 1430, Spring April 21, 2001 ANSWERS

ACTIVANT B2B SELLER B2B SELLER NEW FEATURES GUIDE VERSION 5.8

This application will be processed under the terms of the Agreement between the New Zealand Government and the Government of Malta.

6.2 Normal distribution. Standard Normal Distribution:

Prediction The Evidence it Doesn't Work and a Popular Theory that Leads to Losses

Retirement. Income. your way

Special to the Filipino Reporter

USA & Canada: Tier 4 General Student Visa Immigration Guidance

Claims Management Claim Form. When you have filled in the form, please send it to us at:

SUBNETTING SCENARIO S

MASTER OF SCIENCE IN THE DEPARTMENT OF COMMERCIAL VEHICLE TECHNOLOGY

Concordia University Course Evaluation Survey: Summary Report

ATM/Debit Terms and conditions

Factoring Polynomials

Registration and Licensure as a Pharmacy Technician

Information Collection on DDoS Attacks. Anna Claiborne Prolexic Technologies

Solutions: Sample Exam 2: FINA 5500

Compsci 101: Test 1. October 2, 2013

WebSphere Business Monitor V7.0 Script adapter lab

Big Data Debate Kit Evaluation Report

2014 INA Salary & Benefits Survey International Nanny Association (INA), All Rights Reserved.

WhiteHat SALES TRAINING MULTI TOUCH SALES STRATEGY

National Solidarity Bond - Terms and Conditions Issue 4

Standard 6: The student will explain and evaluate the importance of planning for retirement.

Independent samples t-test. Dr. Tom Pierce Radford University

NERI Quarterly Economic Facts Summer Distribution of Income and Wealth

General Method: Difference of Means. 3. Calculate df: either Welch-Satterthwaite formula or simpler df = min(n 1, n 2 ) 1.

Application Form Guide 2015/2016 How to make an Application for grant funding

>

Quick Steps For Setting Up and Using the CC Merchant Utility

Solutions to Homework 6 Statistics 302 Professor Larget

PowerScore Test Preparation (800)

Configuring a Random Weight Bar Code

Credit Cards and You series. Credit Cards: Understanding. Responsibilities

Easy Casino Profits. Congratulations!!

MAT 155. Key Concept. September 27, S5.5_3 Poisson Probability Distributions. Chapter 5 Probability Distributions

Business Name : Crystal Dental

Online Banking. Making your life easier. Our business is business banking.

Lab 5 Introduction to Java Scripts

FFAVORS FAQs and Tips

EUROPEAN YOUTH: PARTICIPATION IN DEMOCRATIC LIFE

APPLICATION PROCEDURES STEP BY STEP

Transcription:

JavaScript 4 User Input Validation 1

Input Validation User enters data input Validator checks format ok input Server processes it not ok "oops!" One of the most useful applications of JavaScript is input validation Scripts in the page can check that inputs conform to particular formats before sending them to the server This can make for a better user experience, save time and other resources 2

Rep. Ireland Mobile Numbers 08 + 3/5/6/7 + 7 digits Irish mobiles start with 08 followed by either 3, 5, 6, 7 (088 is obsolete now), followed by 7 digits 3

var mobilenum; var valid = new Boolean(true); mobilenum =prompt("please enter your mobile phone number", "0879996666"); if ((mobilenum==null) (mobilenum=="")) valid= false; if (mobilenum.length!= 10) valid=false; if (mobilenum.slice(0,2)!= "08") valid=false; var c = mobilenum.slice(2,3); if (! ((c=="3") (c=="5") (c=="6") (c=="7")) ) valid=false; for (n=3;n<10;n++) { c = mobilenum.slice(n,n+1); if ((c < "0") (c > "9")) valid=false; } 4

Checksum Very often 1 digit of an input is used to detect errors Imagine if the last digit of a phone number was required to be the number of even digits 0879996665 If someone made a mistake it might be detected if the numbers didn t add up 0879996662 - something's wrong! Checksums are not usually so simple and typically applying a multiplier to some of the digits 5

Credit Card Numbers The last digit of a 16- digit credit card number is a check sum It doesn't tell you if the number is valid, or the account has enough money But if the checksum is wrong it can't be correct 6

Luhn Formula for Credit Cards Starting with the second last digit of the number, multiply every second digit by 2 Add all the resulting digits, together with the unmodified digits, and the check sum If the resulting number is evenly divisible by 10 then the checksum is valid 7

Luhn Formula for Credit Cards 4 4 9 9 2 2 8 3 0 8 0 1 7 4 2 2 8 18 4 16 0 0 14 4 1+8 1+6 1+4 8 4 9 9 4 2 7 3 0 8 0 1 5 4 4 2 = 70 70 mod 10 = 0 so checksum is valid 8

Card Prefix Length Visa 4 13 / 16 American Express 34 / 37 15 MasterCard 51-55 16 Discover 6011 16 Diners Club 300-305 / 36 / 38 14 9

International Standard Book Number ISBN Every book has a unique number that identifies the publisher and other information The last digit of the ISBN is a MOD 11 checksum 10

ISBN 0 7 8 7 9 5 1 6 2 5 x 10 9 8 7 6 5 4 3 2 1 0 63 64 49 54 25 4 18 4 5 + 286 MOD 11 = 0 so it's valid 11

ISBN 1 5 6 4 7 8 2 1 4 X x 10 9 8 7 6 5 4 3 2 1 10 45 48 28 42 40 8 3 8 10 + 242 MOD 11 = 0 so it's valid Note that MOD 11 can result in 10. So the last digit may be X = 10. (Roman numbers live!) 12

Modulus Checksums In general the modulus chosen needs to be Greater than the number digits Greater than the range of any single digit Prime numbers work especially well Random ISBN errors have 90% (10/11) chance of being caught. 13

R. Ireland PPS Numbers Every person working in the Republic of Ireland has a PPS number Children are now issued them at birth Organizations that may request and store them are specifically controlled by legislation The number is 7 digits followed by a checksum letter 14

PPSN 6 0 5 9 9 2 2 H x 8 7 6 5 4 3 2 48 0 30 45 36 6 4 Total = 169 169 MOD 23 = 8 = H A B C D E F G H I J K L M N O P Q R S T U V W 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 0 Some woman in Ireland have PPS numbers identical to their husband's, but followed by a W. So there may be 2 letters - a check sum and a W. It is co-incidence that W is the 23rd letter. This W is for "wife". This somewhat sexist practice has been discontinued. 15

Euro banknote serial numbers X04135981862 Convert first letter to a number (A=1, B=2, Z=26) Add up all the digits 24+0+4+1+3+5+9+8+1+8+6+2 =71 Add those together (as often as required) 7+1 = 8 Final result will always be 8 16

Finland's Sosiaaliturvatunnus or SOTU DDMMYYSPPPC DDMMYY - date S is separator + for people born in 1800's - for people born in 1900's A for people born in 2000's PPP is a person number. Even for females an odd for males This means that at most 500 men can be born in Finland is any 1 day! (currently <100) C is checksum Treat DDMMYYPPP as a large number and MOD by 31 MOD is mapped to a single character from 0123456789ABCDEFHJK LMNPRSTUVWXY So if MOD 31 is 15 checksum is E You are not expected to know this for exam purposes 17

Exercises Test ISBNs and random 10 digit numbers with the ISBN checksum Verify your PPSN checksum Verify your credit card checksum Write JavaScript code to validate ISBNs and PPSNs 18

Other Examples P.R. China (mod 11), UK, Italy (mod 26) all use checksums The U.S. and Canada share a numbering system, but only Canadian numbers use a checksum Many barcode systems use a checksum too R. Ireland CAO student numbers use a checksum but the method used is a secret 19