Form Validation

Form Behavior use the OWASP Validation Regex Repository as reference to validate user input. It has 7 types of input / string validations:

  • URL

  • IPV4

  • Email

  • Safe text

  • US Date

  • Credit Card

  • Password

Form Validation is a static class that is used internally in Form Behavior component but you can use to validate any string in your code.

using UnityEngine;
using WeendieGames.FormBehavior;

public class FormBehaviorDemo : MonoBehaviour
{
    //Values
    string email = "contact@weendie.games";
    string ip = "127.0.0.1";

    //Validation Results
    bool emailResult = false;
    bool ipResult = false;

    // Start is called before the first frame update
    void Start()
    {
        //
        emailResult = FormBehaviorData.ValidateString(email, FormBehaviorData.FormatValidation.Email);
        Debug.Log("'"+ email + "' validation result: "+ emailResult);
        //
        ipResult = FormBehaviorData.ValidateString(ip, FormBehaviorData.FormatValidation.IPV4);
        Debug.Log("'" + ip + "' validation result: " + ipResult);
    }

}

Last updated