payload-field-validators
Version:
Easy validation handlers for Payload CMS collection's fields
17 lines (14 loc) • 486 B
text/typescript
import {validateRegex} from '../index.js'
const isIPRegex = /^(?:(?:\d{1,3}\.){3}\d{1,3}|(?:[a-fA-F0-9]{1,4}:){1,7}[a-fA-F0-9]{1,4})$/;
/**
* Wrapper function for checking IP address validation
* @param value the input to be checked
* @param message message to shown if input is invalid
*/
export function validateIPAddress(value: any, message?: string): any {
return validateRegex({
value: value,
regExp: isIPRegex,
message: message || 'Invalid IP address',
})
}