dp_check_var

one of the documented procedures in this installation of the ACS
Usage:
dp_check_var   name   value
What it does:
Checks the value of $name against the type of data that we expect to find. Returns null if the $name looks ok; returns an error otherwise.
Defined in: /web/philip/tcl/data-pipeline-defs.tcl

Source code:



    set type [dp_variable_type $name]
    switch -exact $type {
	phone {
	    ## It's hard to catch all the cases for phone numbers. We just make sure there 
	    ## are at least 10 characters
	    if { ![empty_string_p $value] && [string length $value] < 10 } {
		return "$value doesn't look like a valid phone number - please make sure that you entered in an area code"
	    }} 
	email {
	    ## Email address must be of the form yyy@xxx.zzz
	    if { ![empty_string_p $value] && ![philg_email_valid_p $value] } {
		return "The email address that you typed, $value, doesn't look right to us.  Examples of valid email addresses are 
<ul>
<li>Alice1234@aol.com
<li>joe_smith@hp.com
<li>pierre@inria.fr
</ul>
"
             }}
        expr {
	    ## expressions are a potential security hole IF we allow people to
	    ## put in arbitrary strings. We limit expressions to 1 word (i.e. no
	    ## spaces).
	    set temp $value
	    regsub {^[ ]*} $temp "" temp
	    regsub {[ ]*$} $temp "" temp
            if { [regexp -- { } $temp] } {
                return "'$value' isn't a valid expression. Expressions can only be a single word."
	    }}
        year {
            if [regexp -- {[^0-9]} $value] {
                return "'$value' isn't a valid year"
            } elseif { [string length $value] != 4 } {
                return "A year must be a four-digit number (you entered '$value')"
            }}
        int {
            if [regexp -- {[^0-9]} $value] {
                return "'$value' isn't an integer"
            }}
        money {
	    regsub -all {,} $value {} value
            if {![empty_string_p $value] && [catch {expr $value * 2}]} {
                return "'$value' isn't a real number"
            }}
        date {
	    # We have to rearrange the ascii date format for the ns_buildsqldate function
	    set ymd [split $value {-}]
	    if { [catch { ns_buildsqldate [string trimleft [lindex $ymd 1] "0"] [lindex $ymd 2] [lindex $ymd 0] }] } {
		return "'$value' is not in the proper date format (YYYY-MM-DD)"

	}   }
	}


philg@mit.edu