Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Textbox validation

Textbox validation

Scheduled Pinned Locked Moved Web Development
helpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    si_69
    wrote on last edited by
    #1

    Hi all i have the below functions which i use to validate a login, albeit not very well ! this is called when the user submits the form, all it does it checked they have entered something what i need to do is to throw out an error when a user enters an alpha (a-Z) character as well but im getting a bit stuck, can ne1 point me in the right direction here ??? thanks si function isblank(s) { for(var i=0; i < s.length; i++){ var c=s.charAt(i); if((c!=' ') && (c!='\n') && (c!='\t')) return false; } return true; } function verify(f) { var msg; var empty_fields=""; var errors=""; for (var i=0; i < f.length; i++) { var e = f.elements[i]; if ((e.type == "text") || (e.type == "password")) { if ((e.value=="") || isblank(e.value)){ empty_fields += "\n "+e.name; continue; } } } if (!empty_fields && !errors) return true; msg = "___________________________________________________________\n\n" msg += "The login action could not been performed because of the following error(s).\n"; msg += "___________________________________________________________\n\n"; if(empty_fields){ msg +="The following required field(s) are empty:" + empty_fields + "\n"; if (errors) msg+="\n"; } msg+=errors; alert(msg); return false; }

    G P M 3 Replies Last reply
    0
    • S si_69

      Hi all i have the below functions which i use to validate a login, albeit not very well ! this is called when the user submits the form, all it does it checked they have entered something what i need to do is to throw out an error when a user enters an alpha (a-Z) character as well but im getting a bit stuck, can ne1 point me in the right direction here ??? thanks si function isblank(s) { for(var i=0; i < s.length; i++){ var c=s.charAt(i); if((c!=' ') && (c!='\n') && (c!='\t')) return false; } return true; } function verify(f) { var msg; var empty_fields=""; var errors=""; for (var i=0; i < f.length; i++) { var e = f.elements[i]; if ((e.type == "text") || (e.type == "password")) { if ((e.value=="") || isblank(e.value)){ empty_fields += "\n "+e.name; continue; } } } if (!empty_fields && !errors) return true; msg = "___________________________________________________________\n\n" msg += "The login action could not been performed because of the following error(s).\n"; msg += "___________________________________________________________\n\n"; if(empty_fields){ msg +="The following required field(s) are empty:" + empty_fields + "\n"; if (errors) msg+="\n"; } msg+=errors; alert(msg); return false; }

      G Offline
      G Offline
      Geoff Kushnir
      wrote on last edited by
      #2

      Have you looked into using Regular Expressions? Just because I don't care, doesn't mean I don't understand. - Homer J. Simpson

      1 Reply Last reply
      0
      • S si_69

        Hi all i have the below functions which i use to validate a login, albeit not very well ! this is called when the user submits the form, all it does it checked they have entered something what i need to do is to throw out an error when a user enters an alpha (a-Z) character as well but im getting a bit stuck, can ne1 point me in the right direction here ??? thanks si function isblank(s) { for(var i=0; i < s.length; i++){ var c=s.charAt(i); if((c!=' ') && (c!='\n') && (c!='\t')) return false; } return true; } function verify(f) { var msg; var empty_fields=""; var errors=""; for (var i=0; i < f.length; i++) { var e = f.elements[i]; if ((e.type == "text") || (e.type == "password")) { if ((e.value=="") || isblank(e.value)){ empty_fields += "\n "+e.name; continue; } } } if (!empty_fields && !errors) return true; msg = "___________________________________________________________\n\n" msg += "The login action could not been performed because of the following error(s).\n"; msg += "___________________________________________________________\n\n"; if(empty_fields){ msg +="The following required field(s) are empty:" + empty_fields + "\n"; if (errors) msg+="\n"; } msg+=errors; alert(msg); return false; }

        P Offline
        P Offline
        Populate123
        wrote on last edited by
        #3

        use in this way, first store alpha charcater in string, and then chk character in this string. function isblank(s) { var c; var chkstring="a,b,c,d,e,f...."; for(var i=0; i < s.length; i++){ var c=s.charAt(i); if(chkstring.charAt(c) > 0) { alert("Can not enter a-z messages here"); return false; } } return true; } Himadrish Laha

        1 Reply Last reply
        0
        • S si_69

          Hi all i have the below functions which i use to validate a login, albeit not very well ! this is called when the user submits the form, all it does it checked they have entered something what i need to do is to throw out an error when a user enters an alpha (a-Z) character as well but im getting a bit stuck, can ne1 point me in the right direction here ??? thanks si function isblank(s) { for(var i=0; i < s.length; i++){ var c=s.charAt(i); if((c!=' ') && (c!='\n') && (c!='\t')) return false; } return true; } function verify(f) { var msg; var empty_fields=""; var errors=""; for (var i=0; i < f.length; i++) { var e = f.elements[i]; if ((e.type == "text") || (e.type == "password")) { if ((e.value=="") || isblank(e.value)){ empty_fields += "\n "+e.name; continue; } } } if (!empty_fields && !errors) return true; msg = "___________________________________________________________\n\n" msg += "The login action could not been performed because of the following error(s).\n"; msg += "___________________________________________________________\n\n"; if(empty_fields){ msg +="The following required field(s) are empty:" + empty_fields + "\n"; if (errors) msg+="\n"; } msg+=errors; alert(msg); return false; }

          M Offline
          M Offline
          markkuk
          wrote on last edited by
          #4

          You should start by correcting your basic approach: instead of looking for errors in the input you should be testing for correct input and giving an error message if the test fails. See this article on data validation

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups