Solved

Limit Textbox Entry

Posted on 2003-11-04
2
601 Views
Last Modified: 2012-05-05
I want to limit the text entered into my textbox in the following ways:

If name="Jed" Then
  maxLength="6"
ElseIf name="Ted" Then
  maxLength="5"
Else maxLeength="4"

Also, you can only enter the following characters:
FLAfla1234567890

Also, you can only enter the following combo of letters:
either    FL
or    A

You may only enter one A or you may enter FL or you can enter no letters but numbers only!
0
Comment
Question by:yourbudweiser
[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
2 Comments
 
LVL 3

Expert Comment

by:superslamwich
ID: 9683206
Heres for the entry, I'll get a maxlength script for you in a sec:

<script type='text/javascript'>
<!--

function validate(obj)  {
  val=obj.value
  re1=/(F)/i
  re2=/(L)/i
  re3=/(A)/i
  re4=/(\d+)/
  re5=/[^FLA0-9]/i
  q=0
  if(re1.test(val))  q=q+.5
  if(re2.test(val))  q=q+.5
  if(re3.test(val))  q++
  if(re4.test(val))  q++
  if(re5.test(val))  q=q+2
  if(q==1)  {
    alert("OK")
    return true;
  } else {
    alert("NOT OK")
    return false;
  }
}
//-->
</script>

<form onSubmit='validate(this.form.elements["joe"])'>
<input type='text' name='joe'><br />
<input type='submit value='CLICK'>
</form>
0
 
LVL 3

Accepted Solution

by:
superslamwich earned 75 total points
ID: 9683212
Whoops, make that this:

<script type='text/javascript'>
<!--

function validate(obj)  {
 val=obj.value
 re1=/(F)/i
 re2=/(L)/i
 re3=/(A)/i
 re4=/(\d+)/
 re5=/[^FLA0-9]/i
 q=0
 if(re1.test(val))  q=q+.5
 if(re2.test(val))  q=q+.5
 if(re3.test(val))  q++
 if(re4.test(val))  q++
 if(re5.test(val))  q=q+2
 if(q==1)  {
   alert("OK")
   return true;
 } else {
   alert("NOT OK")
   return false;
 }
}
//-->
</script>

<form onSubmit='return validate(this.elements["joe"])'>
<input type='text' name='joe'><br />
<input type='submit' value='CLICK'>
</form>

{Slam}
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

733 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