isbn

Regular expression for an ISBN 13

北慕城南 提交于 2019-11-28 01:19:41
问题 Hi all I'm trying all the time to make a regular expression for XML in my .xsd . This expression should verify an ISBN-13 number but I couldn't get further than this: ISBN (978|979)[ |-][0-9]{1,5}[ |-][0-9]{1,7}[ |-][0-9]{1,7}[0-9]{1} This is ok if somebody fills in a correct ISBN13, but it is also still possible to make ISBNs which are much longer (for example it is still possible to make the first block of numbers 5 long and the second 7 digits and the third also 7 digits long). I am very

regex differentiating between ISBN-10 and ISBN-13

三世轮回 提交于 2019-11-27 06:36:06
问题 I have an If-else statement which checks a string to see whether there is an ISBN-10 or ISBN-13 (book ID). The problem I am facing is with the ISBN-10 check which occurs before the ISBN-13 check, the ISBN-10 check will match anything with 10 characters or more and so may mistake an ISBN-13 for an ISBN-10. here is the code... $str = "ISBN:9780113411436"; if(preg_match("/\d{9}(?:\d|X)/", $str, $matches)){ echo "ISBN-10 FOUND\n"; //isbn returned will be 9780113411 return 0; } else if(preg_match(