1.0.7 • Published 9 months ago

sensedge-validation v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

Form Validation - User Manual

Version 1.0.6

Document Control Sheet

Why SENSVAL

Traditional validation methods often require users to create separate functions for each input field and form, which can be time-consuming and complex. The sensval library simplifies this process by providing a unified solution for validating all types of input fields and forms. With sensval, users can easily implement validation by adding a data-sensval attribute to the relevant input fields and forms, streamlining the entire process and saving valuable development time.

How to Use

Installation

To use the validation rules outlined in this document, include the sensval.min.js script in your HTML file and apply the data-sensval attribute to the input fields that require validation.

	Ex:
	<script src="sensval.min.js"></script>
	This manual provides detailed instructions on single and multiple validations,
	as well as user-defined validation rules.

Using by NPM

To use the sensedge-validation package through npm.

	Ex:
	<npm install sensedge-validation>

Using By CDN

cdn Link - https://cdn.jsdelivr.net/gh/SENSEDGETSS/sens-validate@main/sensval.min.js

Single Validation

Use the data-sensval attribute to specify what kind of validation you want for each input field. For example, data-sensval="TX" ensures the input contains text only.

	Ex:
	<input type="text" data-sensval="TX">

Multiple Validations:

You can apply more than one validation type to a field by separating them with a ‘hyphen(-)’ in the data-sensval attribute. For example, data-sensval="TX-MN" makes sure the field is both text-only and mandatory.

	Ex:
	<input type=” text” data-sensval= “TX-MN”>

User-Defined Values for Validation:

You can specify extra details for certain validations. For example, if you want to check that a number has exactly 10 digits, use data-sensval="NL#10".

 	Ex:
	<input type=” text” data-sensval=”NL#10-MN”>

Form Validation:

Use a button with an onclick event to trigger the validateForm function. This function calls ValidateAll with the form’s id to check all input fields in the form for validity.

	Ex:
	<form id="formId">
	    <input type="text" data-sensval = "MN">
	    <input type="text" data-sensval = "AN">
	    <button onclick="ValidateAll('formId')">Submit</button>
	</form>

Independent Validation:

By using the data-sensval attribute, each input field can be validated in real-time. This allows validation to occur dynamically, such as when a user changes the input. As soon as the input changes, the specific field is instantly validated, providing immediate feedback and ensuring data accuracy throughout the process.

Validations

AbbreviationField TypeValidation Rule
MNMandatory FieldEnsures that the input is not empty.
EMEmail AddressValidates that the input is a properly formatted email address.
PSPassword StrengthEnsures the password includes uppercase, lowercase, numbers, special characters, and a minimum length defined by the user (e.g., PS#8).
TXText OnlyAllows only letters and spaces in the input field.
NMNumber OnlyAllows numeric characters in the input field.
NLNumber LengthValidates that the length has the exact number of digits specified by the user (e.g., NL#10). Like, Credit Card, CVV, ZipCode, Phone No.....
DTDateEnsures the input is a valid date.
ULURLValidates that the input is a properly formatted URL.
MLMinimum LengthEnsures the input is at least a certain number of characters as defined by the user (e.g., ML#5).
XLMaximum LengthEnsures the input does not exceed a certain number of characters as defined by the user (e.g., XL#20).
CRCheckbox RequiredIt Ensures the checkbox status.
SOSelect OptionEnsures the field does not select a 0th index value.
FTFile TypeEnsures the uploaded file has one of the allowed extensions specified by the user (e.g., FT#pdf, jpg).
IPIP AddressEnsures the input is a valid IPv4 address.
DBDate of BirthEnsures the input date is before today (validates that the user was born before today).
ANAlpha NumericAllows only letters and numbers in the input field.
FLFile LimitLimits the number of files uploaded to a maximum specified by the user (e.g., FL#5).
FSFile SizeEnsures that the uploaded file does not exceed a specified size (in MB) (e.g., FS#2).
MRMinimum RangeEnsures that the numeric input is greater than or equal to a specified minimum (e.g., MR#10).
XRMaximum RangeEnsures that the numeric input is less than or equal to a specified maximum (e.g., XR#100).
SNNo Sequential NumberEnsures the input does not contain a sequence of repeating digits greater than or equal to a user-defined length (e.g., SN#3).
RCNo Repeating CharacterEnsures the input does not contain a sequence of repeating characters greater than or equal to a user-defined length (e.g., RC#3).
CDCurrent Valid DateEnsures the input date is today or a future date.
NSNo Special CharactersEnsures that the input does not contain any special characters.
CECustom ErrorAllows custom validation logic with a custom error message.

Note:

  • “MN” – the Input field Attribute value.
  • “NL#10” – ‘NL’-Mean by the Input Attribute value, 10 Defined the input field minimum length.

code

Correct

Wrong

By Using React Component

Key Functions

  • const isValid = validateAll('validationForm'); this line validates the whole form by that corresponding form Id.
  • Also returns the validation result as a Boolean value (true or false). Using this return value you can execute your code by the validation result. React
1.0.7

9 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago