Skip to Content
NFSFU234FormValidation v3 is here — file upload validation, config-driven rules, and more.
v2 (legacy)validateRadio

validateRadio

The validateRadio function validates a specified radio input field. It checks if a radio button within a group is selected and returns an ErrorMessageInterface.

Works in: HTML5, React JS

ParameterTypeDefaultDescription
radioInputFieldHTMLInputElement | stringundefinedThe radio input field or its ID to validate.
customErrorMessageobject{}Custom error message to return if validation fails.

Usage

Example: Validate a Radio Button Group

// Using with a radio input element const radioElement = document.querySelector('input[name="gender"]'); const result = nfsfu234FormValidation.validateRadio(radioElement, { message: 'Please select a gender.' }); console.log(result); // Using with a radio input element ID const resultById = nfsfu234FormValidation.validateRadio('genderRadioId', { message: 'Please select a gender.' }); console.log(resultById);

See also

Last updated on