UNPKG

@travetto/schema

Version:

Data type registry for runtime validation, reflection and binding.

22 lines (19 loc) 812 B
import { TypedObject } from '@travetto/runtime'; import { Messages } from './messages'; /** * List of common regular expressions for fields */ export const CommonRegExp = { email: /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/, telephone: /^(\+?\d{1,3}(\s*-?\s*|\s+))?((\(\d{3}\))|\d{3})(\s*|-|[.])(\d{3})(\s*|-|[.])(\d{4})(\s+(x|ext[.]?)\s*\d+)?$/, url: /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/, simpleName: /^([a-zA-Z\u0080-\u024F]{0,100}(?:. |-| |')){0,10}[a-zA-Z\u0080-\u024F]+$/, postalCode: /^\d{5}(?:[-\s]\d{4})?$/ }; export const CommonRegExpToName = new Map<RegExp, string>(); // Rebind regexes for (const k of TypedObject.keys(CommonRegExp)) { const name = `[[:${k}:]]`; CommonRegExpToName.set(CommonRegExp[k], name); Messages.set(name, Messages.get(k)!); }