ASP simple form validation - changing?

I'm trying to do a very basic form validation check for null or '' (empty) using a conditional expression, but when I submit my form with all BLANK FIELDS, it does the last section of my code.

And when I fill in all my fields, it does this other part. So when they are empty, tell the user which is the first section of the conditional, I pasted my code below. Any suggestions on what I can do? This is my "OR" or "AND"

if(((f_name <> null) or (f_name <> "")) or ((l_name <> null) or (l_name <> "")) or ((username <> null) or (username <> "")) or ((password <> null) or (password <> ""))) then
    'response.redirect("account_created.asp")
    response.write("You have not filled in all fields.")
else
    Set objConn = ConnectDB()
    query       = "INSERT INTO [user] (username,[password],f_name,l_name) VALUES ('"& username &"','"& password &"','"& f_name &"','"& l_name &"')"
    Set objs    = objConn.Execute(query)
    response.write(query)
    'Response.Redirect ("thankyou.asp")

end if

      

+1


source to share


2 answers


  • You don't need all the parentheses
  • If fname and others are text fields, you need fname.Text instead


-1


source


In general, it should be sufficient to check for an empty string (eg f_name <> ""). However, I usually do this with crop and line. len (trim (f_name))> 0. It takes care of all whitespace. You should revise your parenthesis as they are unnecessary. if len (trim (f_name))> 0 or ... then



0


source







All Articles