I'm trying to get a regex that validates ISBN 10 and ISBN 13
"978-1-56619-909-4 2" => false
"978-1-56619-909-4" => true
"1-56619-909-3 " => false
"1-56619-909-3" => true
"isbn446877428ydh" => false
"55 65465 4513574" => false
"1257561035" => true
"1248752418865" => true
"978-8445073728" => true
"841671603X" => true
"1-56619-909-X" => true
"12-48752-41-8-8-6-5" => false
This regex I found is almost perfect ^(?=(?:\D*\d){10}(?:(?:\D*\d){3})?$)[\d-]+$
but... "841671603X" will return false and "12-48752-41-8-8-6-5" will return true.
- For ISBN10 I want to be true 10 digits in only these formats:
"1-56619-909-3"
"1257561035"
"1-56619-909-X"
"841671603X"
- For ISBN13 I want to be true 13 digits in only these formats:
"978-1-56619-909-4"
"978-8445073728"
"1248752418865"
If you could help me, I'd appreciate it a lot.
Thank you in advance.
Best Regards.