Solved

Limit Textbox Entry

Posted on 2003-11-04
2
596 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now