Skip to main content
Glama
validatePhone.ts757 B
import { validateString } from './validateString'; /** * Validates a email field. * @param value The value to validate. * @param entityName The name of the entity being validated. * @param minLength The minimum length of the string. * @param maxLength The maximum length of the string. * @returns An array of validation errors. */ export const validatePhone = ( value: unknown, entityName = 'Phone', minLength = 6, maxLength = 20 ): string[] => { const errors = validateString(value, entityName, minLength, maxLength); const phoneRegex = /^\+?\(?\d{3}\)?[-\s.]?\d{3}[-\s.]?\d{4,6}$/; if (typeof value === 'string' && !phoneRegex.test(value)) { errors.push(`${entityName} must be a valid phone number.`); } return errors; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server