validation-box
Version:
The only validation library - with flexible regex - you need.
1 lines • 1.12 kB
Source Map (JSON)
{"version":3,"sources":["../src/validators/countries/usa.ts"],"sourcesContent":["// Validation of SSN (Social Security Number) in the USA\r\nexport const validateSSN = (ssn: string): boolean => {\r\n return /^\\d{3}-\\d{2}-\\d{4}$/.test(ssn);\r\n};\r\n\r\n// Validation of phone number in the USA\r\nexport const validatePhoneUS = (\r\n phone: string,\r\n requireCountryCode: boolean = false\r\n): boolean => {\r\n const countryCodeRegex = requireCountryCode ? \"(\\\\+1|1)\" : \"(\\\\+1|1)?\";\r\n const regex = new RegExp(\r\n `^${countryCodeRegex}\\\\s?\\\\d{3}\\\\s?\\\\d{3}\\\\s?\\\\d{4}$`\r\n );\r\n return regex.test(phone);\r\n};\r\n\r\n// Validation of ZIP code in the USA\r\nexport const validateZIPCode = (zipCode: string): boolean => {\r\n return /^\\d{5}(-\\d{4})?$/.test(zipCode);\r\n};\r\n"],"mappings":";AACO,IAAM,cAAc,CAAC,QAAyB;AACnD,SAAO,sBAAsB,KAAK,GAAG;AACvC;AAGO,IAAM,kBAAkB,CAC7B,OACA,qBAA8B,UAClB;AACZ,QAAM,mBAAmB,qBAAqB,aAAa;AAC3D,QAAM,QAAQ,IAAI;AAAA,IAChB,IAAI,gBAAgB;AAAA,EACtB;AACA,SAAO,MAAM,KAAK,KAAK;AACzB;AAGO,IAAM,kBAAkB,CAAC,YAA6B;AAC3D,SAAO,mBAAmB,KAAK,OAAO;AACxC;","names":[]}