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
Medium Priority
143 Views

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
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

LVL 28

Accepted Solution

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

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

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…
###### Suggested Courses
Course of the Month4 days, 17 hours left to enroll