Class: H_validator

H_validator

HTML form validation class with event handling and input controls
Essentialy called and used automaticaly by H.php class on inputs of forms...

new H_validator()

validator.js, line 31

Methods

bad_field_modal(input)

validator.js, line 652
Displays an error modal for an invalid field
Name Type Description
input HTMLInputElement The field concerned by the error

check_date(dateString){boolean}

validator.js, line 727
Validates date format, it's a dummy function because the navigator validate automaticaly the datetime tag actually.
Name Type Description
dateString string The date string to validate
Returns:
Type Description
boolean true if the date is valid

check_email(email){boolean}

validator.js, line 691
Validates email address format
Name Type Description
email string The email address to validate
Returns:
Type Description
boolean true if the email is valid
Example
validator.check_email('test@example.com'); // returns true
validator.check_email('invalid-email'); // returns false

check_field(input){boolean}

validator.js, line 389
Checks the validity of an individual field Applies appropriate CSS classes and manages error display
Name Type Description
input HTMLInputElement The field to check
Returns:
Type Description
boolean true if the field is valid

check_float(str){boolean}

validator.js, line 838
Checks if a string represents a valid floating point number
Name Type Description
str string The string to check
Returns:
Type Description
boolean false if the string is not a valid floating point number
Example
validator.check_float('123.45'); // returns true
validator.check_float('12,34'); // returns true
validator.check_float('abc'); // returns false

check_form(formDomObject){boolean}

validator.js, line 347
Checks the validity of all form fields
Name Type Description
formDomObject HTMLFormElement The form to check
Returns:
Type Description
boolean true if all fields are valid

check_input_limits(input){number}

validator.js, line 1009
Check if int input value in min/max limit
Name Type Description
input HTMLInputElement to check
Returns:
Type Description
number H_validator.OK, H_validator.too_small, or H_validator.too_big

check_int(str){boolean}

validator.js, line 825
Checks if a string represents a valid integer
Name Type Description
str string The string to check
Returns:
Type Description
boolean false if the string is not a valid integer
Example
validator.check_int('123'); // returns true
validator.check_int('12.3'); // returns false
validator.check_int('abc'); // returns false

check_text(str, restriction, exclusion){boolean}

validator.js, line 799
Checks if a string contains only allowed characters
Name Type Description
str string The string to check
restriction string optional Allowed characters or predefined filter name
exclusion string optional Forbidden characters or predefined filter name
Returns:
Type Description
boolean false if the string contains unauthorized characters
Example
validator.check_text('abc123', '_username'); // returns true
validator.check_text('abc@123', '_username'); // returns false

display_error_field(input, err_list)

validator.js, line 596
Displays error messages for a given field Creates a parent container if necessary and displays errors
Name Type Description
input HTMLInputElement The field concerned
err_list Array.<string> List of error codes to display

evaluate_size(input){number}

validator.js, line 847
Evaluates if a field size respects min/max constraints
Name Type Description
input HTMLInputElement The field to evaluate
Returns:
Type Description
number H_validator.OK, H_validator.too_small, or H_validator.too_big

on_submit_form(event, confirmed){boolean}

validator.js, line 164
Event handler for form submission Checks form validity before submission
Name Type Description
event Event The submission event
confirmed boolean optional Indicates if the submission has been confirmed
Returns:
Type Description
boolean true if submission can continue

on_submit_form_confirmed(formDomObject){boolean}

validator.js, line 226
Processes the confirmed form submission Prepares data and launches sending according to configuration
Name Type Description
formDomObject HTMLFormElement The form to submit
Returns:
Type Description
boolean false (prevents default submission)

parse_fields(formDomObject){boolean}

validator.js, line 55
Parses and prepares all fields of a form for validation Configures events and navigation between fields
Name Type Description
formDomObject HTMLFormElement | string The DOM object of the form or its ID
Returns:
Type Description
boolean false if the form is not found
Example
const validator = new H_validator();
validator.parse_fields('myForm');

restrict_string(str, restriction, exclusion){string}

validator.js, line 987
Filter string to keep only authorized chars.
Name Type Description
str string to filter
restriction string optional Chars authorized only
exclusion string optional Chars rejected only
Returns:
Type Description
string string filtered
Example
validator.restrict_string('abc@123', '_username'); // returns 'abc123'

send_form(settings)

validator.js, line 338
Sends the form via AJAX
Name Type Description
settings Object The sending parameters

validate_date(dateString){string}

validator.js, line 737
Validates and formats a date string Automatically corrects out-of-bounds values
Name Type Description
dateString string The date string to validate
Returns:
Type Description
string The formatted and validated date

staticH_validator.convert_string_filter(restriction){string}

validator.js, line 766
Converts predefined string filters to valid character strings
Name Type Description
restriction string The filter name to convert
Returns:
Type Description
string The corresponding valid character string
Example
H_validator.convert_string_filter('_username'); // returns username valid chars
H_validator.convert_string_filter('_alpha'); // returns alphabetic chars