type-r2
Version:
Serializable, validated, and observable data layer for modern JS applications
11 lines (7 loc) • 327 B
text/typescript
import { AttributeCheck, type } from 'type-r';
const ipPattern = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
export function isIPAddress( x : string ) {
return !x || ipPattern.test( x );
}
(isIPAddress as AttributeCheck).error = 'Not valid IP address'
export const IPAddress = type( String ).check( isIPAddress );