Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Field Length Validation

Posted on 1998-10-27
2
Medium Priority
?
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

670 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