Solved

Field Length Validation

Posted on 1998-10-27
2
140 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 30 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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 Month10 days, 20 hours left to enroll

628 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