Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Field Length Validation

Posted on 1998-10-27
2
Medium Priority
?
146 Views
Last Modified: 2008-01-16

 
I would Like to write a function that validates the lenght of a field (Textbox).
ex:
<input type="TextBox" name="Field1" value="" onblur="ValidateLength(10);" > 
ValidateLength function should return a false if the value of field has more than 10 chars.  
 
0
Comment
Question by:Roham
2 Comments
 
LVL 28

Accepted Solution

by:
sybe earned 60 total points
ID: 1273079
<script>
function ValidateLength(field, nr) {
  if (field.value.length > nr) {
    alert('don't enter more then ' + nr + ' characters');
    field.focus();
  }
}

</script>

<input type="TextBox" name="Field1" value="" onblur="ValidateLength(this,10);" > 
0
 

Expert Comment

by:Roham1
ID: 1273080
<input type="TextBox" name="Field1" value="" OnKeyPress="AllowNumbersOnly();" > 

function AllowNumbersOnly(){
   if ((event.keyCode < 48) || (event.keyCode > 57))event.returnValue = false;
}

This only works in IE 3 and Above
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question