summaryrefslogtreecommitdiffstats
path: root/rust/src/api_helpers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/api_helpers.rs')
-rw-r--r--rust/src/api_helpers.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs
index 489631b3..020aad76 100644
--- a/rust/src/api_helpers.rs
+++ b/rust/src/api_helpers.rs
@@ -181,7 +181,7 @@ pub fn check_issn(raw: &str) -> Result<()> {
pub fn check_orcid(raw: &str) -> Result<()> {
lazy_static! {
- static ref RE: Regex = Regex::new(r"^\d{4}-\d{4}-\d{4}-\d{4}$").unwrap();
+ static ref RE: Regex = Regex::new(r"^\d{4}-\d{4}-\d{4}-\d{3}[\dX]$").unwrap();
}
if RE.is_match(raw) {
Ok(())
@@ -193,6 +193,14 @@ pub fn check_orcid(raw: &str) -> Result<()> {
}
}
+#[test]
+fn test_check_orcid() {
+ assert!(check_orcid("0123-4567-3456-6789").is_ok());
+ assert!(check_orcid("0123-4567-3456-678X").is_ok());
+ assert!(check_orcid("01234567-3456-6780").is_err());
+ assert!(check_orcid("0x23-4567-3456-6780").is_err());
+}
+
// TODO: make the above checks "more correct"
// TODO: check ISBN-13
// TODO: check hashes (SHA-1, etc)