Solved

Limit Textbox Entry

Posted on 2003-11-04
2
598 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i get the length? 7 33
Window.Open() is showing a blank page 9 31
Delay Form Submission without touching existing code? 5 23
Hide cell in a table 2 13
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…
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…
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…

773 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