Sha256: 6e8d2daaa2af4307fd56e83d878e0c49e6b5e4b9a61479a8a94b4fe1625dc616
Contents?: true
Size: 761 Bytes
Versions: 104
Compression:
Stored size: 761 Bytes
Contents
unit uISBNVerifier; interface type TIsbn = class public class function isValid(aInput: string): Boolean; end; implementation uses sysutils, RegularExpressions; { TIsbn } class function TIsbn.isValid(aInput: string): Boolean; var wrkStr: string; sum, weight, digit, i: integer; begin result := false; wrkStr := aInput.replace('-',''); if TRegex.IsMatch(wrkStr, '^(\d{9}[\dX])$') then begin sum := 0; weight := 10; digit := 0; for i := low(wrkStr) to high(wrkStr) do begin if (wrkStr[i] = 'X') and (i = 10) then digit := 10 else digit := string.ToInteger(wrkStr[i]); sum := sum + (digit * weight); dec(weight); end; result := sum mod 11 = 0; end; end; end.
Version data entries
104 entries across 104 versions & 1 rubygems