From: Josef 'Jupp' Schugt Date: 2002-10-27T01:46:59+09:00 Subject: Validating ISBN: Regex question Hi! I'm using the following method to validate an ISBN, remove any ' ' or '-' from it and and change 'x' to 'X'. |def validate_isbn! | match = /(\d)[- ]?(\d)[- ]?(\d)[- ]?(\d)[- ]?(\d)[- ]?(\d)[- ]?(\d)[- ]?(\d)[- ]?(\d)[- ]?([0-9xX])/.match(@isbn) | if match == nil | return 'ISBN pattern mismatch' | end | checksum = 0 | @isbn = '' | for i in 1..10 | case match[i] | when 'X', 'x' | checksum += 10 | @isbn += 'X' | else | checksum += (11 - i) * match[i].to_i | @isbn += match[i] | end | end | (checksum.remainder(11) == 0 ? '' : 'in') + 'valid checksum' |end I'm not to happy about the lenghty regex but I don't see how to make it shorter because using | match = /(\d[- ]?){9,9}([0-9xX])/.match(@isbn) is not possible - it does not split the ISBN into it's digits. Is there any elegant solution to this? Josef 'Jupp' Schugt