Skip to main content

Get regex patterns for field validation by country

GET 

/company/country/regex/:code

Returns regular expression patterns organized by country code for validating specific formats of fields such as tax IDs, phone numbers, vehicle license plates, and email addresses.

Objective

Enable client-side and server-side validation of user-provided data according to the specific format requirements of each country. This ensures data quality and compliance with regional standards.

Use Cases

  • Validate tax identification numbers (NIF, CIF, VAT) during company registration
  • Verify phone number formats before storing contact information
  • Check license plate formats when registering trucks
  • Validate email address formats using a generic pattern

Validation Flow

flowchart TD
A[Client request with code parameter] --> B{Valid code type?}
B -->|taxID| C[Return tax ID patterns for 15 countries]
B -->|phoneNumber| D[Return phone patterns for 46+ countries]
B -->|plate| E[Return license plate patterns for 3 countries]
B -->|email| F[Return generic email pattern]
B -->|Other| G[Return empty object]
C --> H[200 OK with country:regex map]
D --> H
E --> H
F --> H
G --> H

Response Structure

The response is a map where the keys are country codes (2-letter ISO codes) and the values are regex strings.

Important Notes:

  • Country codes may be in UPPERCASE or lowercase depending on the validation type
  • taxID: codes in lowercase (es, pt, fr, it, de, lu, pl, se, dk, nl, be, gb, ie, ad, ch)
  • phoneNumber: codes in UPPERCASE + ALL for the generic pattern
  • plate: codes in UPPERCASE (ES, FR, PT)
  • email: only ALL key with generic email regex
  • Invalid codes return an empty data object {status: 200, data: {}}
  • Regex patterns are loaded from src/features/common/regEx.json

Authentication

This is a PUBLIC endpoint. No authentication is required.

Request Examples:

# Get tax ID validation patterns for all supported countries
GET /company/country/regex/taxID

# Get phone number validation patterns
GET /company/country/regex/

<Heading
id={"request"}
as={"h2"}
className={"openapi-tabs__heading"}
children={"Request"}
>
</Heading>

<ParamsDetails
parameters={[{"name":"code","in":"path","description":"Validation pattern type to retrieve.\n\nValid values:\n- `taxID`: Tax identification numbers (NIF, CIF, VAT, etc.)\n- `phoneNumber`: International phone number formats\n- `plate`: Vehicle license plate formats\n- `email`: Email address format (generic)\n\nInvalid values will return an empty data object without error.","required":true,"schema":{"type":"string","enum":["taxID","phoneNumber","plate","email"],"example":"taxID"}}]}
>

</ParamsDetails>

<RequestSchema
title={"Body"}
body={undefined}
>

</RequestSchema>

<StatusCodes
id={undefined}
label={undefined}
responses={{"200":{"description":"Successful operation. Returns a dictionary of regex patterns organized by country code.\n\nThe response structure is always `{status: 200, data: {...}}` where data contains the regex map.\n\n**Coverage by type**:\n- `taxID`: 15 European countries\n- `phoneNumber`: 46+ countries including the generic ALL pattern\n- `plate`: 3 countries (ES, FR, PT)\n- `email`: Generic pattern with key ALL","content":{"application/json":{"schema":{"type":"object","required":["status","data"],"properties":{"status":{"type":"integer","description":"HTTP status code","example":200},"data":{"type":"object","description":"Dictionary that maps country codes to regex patterns.\nKeys are 2-letter ISO country codes or ALL for generic patterns.\nValues are regex strings ready to use with `new RegExp()`.","additionalProperties":{"type":"string","pattern":"^.*$","description":"Regular expression pattern for the requested validation type"},"example":{"es":"^([XYZ]\\d{7}[A-Z]|\\d{8}[A-Z]|[A-Z]\\d{7}[A-Z]|[A-Z]\\d{8})$","pt":"^[0-9]{9}$","fr":"^(FR)?[0-9A-Z]{2}\\d{9}$"}}}},"examples":{"taxIDExample":{"summary":"Tax ID patterns (taxID)","description":"Returns tax identification validation patterns for 15 European countries.","value":{"status":200,"data":{"pt":"^[0-9]{9}$","es":"^([XYZ]\\d{7}[A-Z]|\\d{8}[A-Z]|[A-Z]\\d{7}[A-Z]|[A-Z]\\d{8})$","fr":"^(FR)?[0-9A-Z]{2}\\d{9}$","it":"^\\d{11}$","de":"^\\d{9}$","lu":"^\\d{8}$","pl":"^\\d{10}$","se":"^\\d{10}$|^\\d{12}$","dk":"^\\d{8}$","nl":"^(NL)?\\d{9}B\\d{2}$","be":"^\\d{10}$","gb":"^(GB)?\\d{9}$|^(GB)?\\d{12}$|^GD\\d{3}$|^HA\\d{3}$","ie":"^\\d{7}[A-Z]{1,2}$|^\\d[A-Z+*]\\d{5}[A-Z]$","ad":"^[A-Z]{2}\\d{6}[A-Z]$","ch":"^CHE-\\d{3}\\.\\d{3}\\.\\d{3}(MWS)?$"}}},"phoneNumberExample":{"summary":"Phone number patterns (phoneNumber)","description":"Returns phone validation patterns for 46+ countries plus the generic pattern.","value":{"status":200,"data":{"ES":"^(?:\\+34|0034|34)?[1-9]\\d{8}$","FR":"^(?:\\+33|0033|33)?[1-9]\\d{8}$","PT":"^(?:\\+351|00351|351)?[1-9]\\d{8}$","IT":"^(?:\\+39|0039|39)?\\d{10}$","DE":"^(?:\\+49|0049|49)?[1-9]\\d{10}$","ALL":"^(?:\\+\\d{1,3}|00\\d{1,3})?\\d{7,12}$"}}},"plateExample":{"summary":"License plate patterns (plate)","description":"Returns license plate validation patterns for Spain, France, and Portugal.","value":{"status":200,"data":{"ES":"^[0-9]{4}[BCDFGHJKLMNPQRSTVWXYZ]{3}$","FR":"^[A-Z]{2}-[0-9]{3}-[A-Z]{2}$","PT":"^[0-9]{2}-[0-9]{2}-[A-Z]{2}-[0-9]{1}$"}}},"emailExample":{"summary":"Email pattern (email)","description":"Returns the generic email validation pattern","value":{"status":200,"data":{"ALL":"^[A-Za-z0-9_!#$%&'*+/=?`{|}~^.-]+@[A-Za-z0-9.-]+$"}}},"emptyExample":{"summary":"Invalid code returns empty data","description":"When an invalid code is provided, it returns an empty data object.","value":{"status":200,"data":{}}}}}},"headers":{}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"type":"object","required":["status","message"],"properties":{"status":{"type":"integer","description":"HTTP status code","minimum":400,"maximum":599,"example":400},"message":{"type":"string","description":"Error code from the system.\n\nCommon error codes (see listado_errores_http.txt for complete list):\n- NO_TOKEN (401): JWT token not provided\n- TOKEN_NOT_VALID (401): JWT token is invalid or expired\n- NO_ADMIN_ROLE (401): User does not have admin privileges\n- INVALID_PARAMETERS (400): Request parameters are invalid\n- NOT_FOUND (404): Requested resource not found\n- ALREADY_EXIST (401): Resource with same identifier already exists\n- UTC_VALIDATION_FAILED (400): UTC timestamp validation failed\n- INTERNAL_ERROR (500): Unexpected server error occurred\n\nThe message is resolved by `handlerError.getErrorMessage(error)`.","example":"INVALID_PARAMETERS"}},"description":"Standard error response format used across all API endpoints.\n\nAll errors follow the pattern `{status: number, message: string}`.\nThe status code is repeated in both the HTTP response and the body.\n\nError messages are constants defined in the codebase and should be\nhandled on the client side with appropriate user-facing messages.","example":{"status":400,"message":"INVALID_PARAMETERS"},"title":"ErrorResponse"},"example":{"status":500,"message":"INTERNAL_ERROR"}}}}}}
>

</StatusCodes>