Solved

Field Length Validation

Posted on 1998-10-27
2
134 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 30 total points
Comment Utility
<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
Comment Utility
<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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
JDeveloper 12c for 32 bit 4 30
Using this to set a value in javascript 1 25
Problem to Popup 2 47
Hidden Field Value 10 32
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now