Solved

Limit Textbox Entry

Posted on 2003-11-04
2
599 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
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

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

837 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