Getting Started
Overview
Installation
Theme
Forms
Basic Inputs
Select
Custom Inputs
Components
Navigation
Components
69
Micro Charts
Libraries
Kanban Board
Image Designer
Video Player
Visual Builder
Content Editor
Data View
Latest npm version of @ngstarter-ui/componentsWeekly npm downloads of @ngstarter-ui/components
Purchase

Input Validator

Input Validator provides ready-made Angular ValidatorFn functions for common form rules. Use these validators with FormControl, Validators.compose, NgStarter ngs-form-field, and ngs-error.

The current preset validators focus on payment fields: creditCardNumberValidator(), expiryDateValidator(), and creditCardCvvValidator(). They pair naturally with the credit card masks from Input Mask, but they do not format values themselves.

Do not use Input Validator as a UI component, input mask, replacement for Angular built-in validators, backend validation, payment processor validation, or security/compliance layer. Use it as a client-side helper for common reusable validation rules.

The NgStarter Angular Input Validator component lets you provide ready-made Angular ValidatorFn helpers for common reusable form validation rules. Use in reactive forms with ngs-form-field, ngsInput, Angular Validators, and ngs-error when a preset client-side validator fits. It includes examples for Credit card input validators.

Credit card input validators

Input Validator includes preset Angular validator functions for credit card number, expiry date, and CVV/CVC. Use them with reactive forms and display messages through ngs-error.

creditCardNumberValidator() checks the cleaned card number length and Luhn checksum. expiryDateValidator() expects MMYY, rejects invalid months, and rejects dates in the past. creditCardCvvValidator() checks numeric CVV/CVC length, with optional min and max length settings.

These validators do not format input values. Pair them with Input Mask directives when users need formatted payment fields.