Create validate.py
Browse files- core/validate.py +13 -0
core/validate.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
|
| 3 |
+
CAS_RX = re.compile(r"^\d{2,7}-\d{2}-\d$")
|
| 4 |
+
DTXSID_RX = re.compile(r"^DTXSID\d{7,}$")
|
| 5 |
+
|
| 6 |
+
def is_cas(s: str) -> bool:
|
| 7 |
+
return bool(CAS_RX.match((s or "").strip()))
|
| 8 |
+
|
| 9 |
+
def normalize_cas(s: str) -> str:
|
| 10 |
+
return (s or "").strip()
|
| 11 |
+
|
| 12 |
+
def is_dtxsid(s: str) -> bool:
|
| 13 |
+
return bool(DTXSID_RX.match((s or "").strip()))
|