有没有办法在存储到数据库之前检查 ISBN 号码是否有效
我想知道是否有一个网络服务或数据库可以让我们在将用户输入存储到数据库之前以编程方式检查用户输入是否是有效的 ISBN 编号。或者是否有一种算法可以让程序员做到这一点
I was wonder is a there a web service or a database out there that let us programmatically check if the user input is an valid ISBN number before storing it in the database. Or is there a algorithm that allow the programmer to do that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果查看维基百科页面,他们有一个简单的算法来确保 ISBN 有效:
当然,这并不能确保它是真实的,只是可能;)
编辑:这包括 ISBN 13 规范:(未经测试,并且与维基百科函数使用相同的伪代码)
If look on the Wikipedia page, they have a simple algorithm to ensure than an ISBN is valid:
Of course, this doesn't ensure that it's real, only possible ;)
EDIT: This includes the ISBN 13 spec: (It's untested, and in the same pseudo-code as the wikipedia function)
您可以尝试:
http://isbndb.com/docs/api/
you might try:
http://isbndb.com/docs/api/
您可以根据以下算法计算校验和: http://en.wikipedia.org/wiki/International_Standard_Book_Number #Check_digits。这并不能告诉您是否确实有一本书具有该编号,但它可以告诉您该编号是否正确。
You could calc the checksum according to this algorithm: http://en.wikipedia.org/wiki/International_Standard_Book_Number#Check_digits. That doesn't tell you if there is actually a book with that number but it tells you if the number is correct.
血淋淋的细节在这里。因此,您可以检查校验位并尝试推断国家(也许还有出版商)是什么,但我没有看到任何方法来检查是否有一本带有该编号的真实书籍
Gory details here. So you can check the check digit and have a go at deducing what the country (and maybe publisher) are, but I don't see any way of checking there's a real book with that number
要仅验证校验位,而不是与已知的书籍列表进行比较,您可以使用 Apache Commons ISBNValidator 类。
代码示例来自:
https:// /apache.googlesource.com/commons-validator/+/trunk/src/test/java/org/apache/commons/validator/ISBNValidatorTest.java
参考文献:
https://commons.apache .org/proper/commons-validator/apidocs/org/apache/commons/validator/routines/ISBNValidator.html
To validate just the checkdigit, and not compare against a known list of books, you could use the Apache Commons ISBNValidator class.
Code example from:
https://apache.googlesource.com/commons-validator/+/trunk/src/test/java/org/apache/commons/validator/ISBNValidatorTest.java
References:
https://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/routines/ISBNValidator.html
正如其他人在我的快速搜索中建议的那样,请尝试: idbndb
As others have suggested in my quick searches on SO try: idbndb