To use this website fully, you first need to accept the use of cookies. By agreeing to the use of cookies you consent to the use of functional cookies. For more information read this page.

Official ZPE/YASS documentationinput_validate

input_validate (function f, string failure_message, [integer max_times]) ⇒ string

Runs a standard input validation algorithm that will wait for the user to enter a valid response. Using a lambda function or a function call, this method can use a custom validation tool. If the max_times parameter is set, the validation will run a maximum of that number of times before stopping and throwing an invalid input error.

First available: Version 1.7.3

Examples

The following examples demonstrate this function:

YASS
function check($x)
  if ($x == "password")
    return true
  else
    return false
  end if
end function
$v = input_validate(handle_of(check), "Incorrect password.")

print($v)
    

The next example use input validation to check that a number is within a range:

YASS
$num = input_validate(
  function($x)
    $x = value($x)
    if ($x > 10 && $x < 100)
      return true
    else
      return false
    end if
  end function
, "Number must be between 10 and 100.")

print($num)
    

This example, submitted to me by one of the testers was based on something she had written before that inspired this and uses regexps:

YASS
$name = input_validate(
  function($x)
    if (string_matches($x, "[A-Z][a-z]+"))
      return true
    else
      return false
    end if
  end function
, "Name must start with a capital and contain at least one lower case character after.")

print($name)
    
Comments

There are no comments on this page.

New comment
Reply
Provide feedback on this page
Comments are sent via email to me.