473,657 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

First Character of form field.

Morning all,

I have a form field called:
Bsk01

How do I onBlur prompt the user to enter a ZERO as character one, if one is
not already entered. At the same time, I would like to ensure at least 5t
characters have been entered. This validation should also only trigger if
anything is entered. Basically, if the user chooses to enter nothing then
the check should not be carried out and the user should be able to continue.

So in pseudo style:

If user data IS ENTERED AND DOES NOT contain a ZERO as first character, or
is LESS THAN 5 characters long, prompt for re-entry.

Thanks guys, been trying various things and got close, but have hit a brick
wall.

This ALMOST works:
function checkField()
{if (document.form1 .Bsk01.value.le ngth<9) {alert("Please enter a valid code.
The first character should be a zero.")}else if
(/^0.*$/.test(document. form1.Bsk01.val ue)){return;}el se{alert("Pleas e enter
a valid code. The first character should be a zero.")}}
Gary.
Jul 20 '05 #1
2 1973
> This ALMOST works:
function checkField()
{if (document.form1 .Bsk01.value.le ngth<9) {alert("Please enter a valid code. The first character should be a zero.")}else if
(/^0.*$/.test(document. form1.Bsk01.val ue)){return;}el se{alert("Pleas e enter a valid code. The first character should be a zero.")}}


Sorry should have said. The problem with the above code is that it always
validates, regardless of data being present. If I try and add
if (document.form1 .Bsk01.value.le ngth>0 &&
document.form1. Bsk01.value.len gth<9)
Then the final condition is always returned which always reports to the user
that the data is incorrect. This is because this code says:

If DATA ENTERED > 0 < 5.
Start Check
IF data LESS THAN 5
Report Error
ELSE IF Character one = 0 AND data more than 5.
Return
Else
Report Error due to no 0.

So when a user enters nothing, the first two conditions are not met,
therefore the final; one always applies.

Gary.
Jul 20 '05 #2
Gary wrote:
Morning all,

I have a form field called:
Bsk01

How do I onBlur prompt the user to enter a ZERO as character one, if one is
not already entered. At the same time, I would like to ensure at least 5t
characters have been entered. This validation should also only trigger if
anything is entered. Basically, if the user chooses to enter nothing then
the check should not be carried out and the user should be able to continue.

So in pseudo style:

If user data IS ENTERED AND DOES NOT contain a ZERO as first character, or
is LESS THAN 5 characters long, prompt for re-entry.

Thanks guys, been trying various things and got close, but have hit a brick
wall.

This ALMOST works:
function checkField()
{if (document.form1 .Bsk01.value.le ngth<9) {alert("Please enter a valid code.
The first character should be a zero.")}else if
(/^0.*$/.test(document. form1.Bsk01.val ue)){return;}el se{alert("Pleas e enter
a valid code. The first character should be a zero.")}}
Gary.


First of all, why don't you pass a value to the function?

function checkField(fiel d){
if(!field.value ){
return true;
}
msg=""
if (field.value.le ngth<9) {
msg+="Please enter a valid code.\n";
}
if(field.value. charAt(0) != "0"){
msg+="The first character should be a zero";
}
if(msg){
alert(msg);
return false;
}
return true;
}

<input name="Bsk01" type ="text" onblur="checkFi eld(this)">
or
<form onsubmit="retur n checkField(this .Bsk01)">

Mick

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6675
by: Noah | last post by:
I have a text field in a form. I want the user to be able to click a DELETE button and have the character at the cursor position deleted. This would be just as if the user had pressed the Back Space key on the keyboard... But this is for a kiosk application with no keyboard :-( so I need to program a delete button. I have code that lets me insert text at the cursor position. And I can move the ABSOLUTE cursor position from the start and...
4
6793
by: Chuck | last post by:
Is there anything in Access 97 that works like *Find* in Excel 97 to find a single character within a text field? Chuck ....
5
5249
by: tdmailbox | last post by:
I have a form with a child form. In the child form there is a list of names that can grow quite large. On the parent form I want to display the first name from the child form. I set up a test box that is populated with the code =subfrm_media_review_sec_party.Form!first_name & " " & subfrm_media_review_sec_party.Form!last_name It works except that when I flip through the names it populates the parent form with the name of what ever...
9
10097
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control, possibly a custom validator with a function written in javascript. Has anyone done this? Does someone have an example? Regards
17
3539
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is populated when a user scans a label. The other is ScanDate - a date/time field that should equal the date/time of the scan (e.g. 7/31/2006 5:00:00 AM).
44
9465
by: Kulgan | last post by:
Hi I am struggling to find definitive information on how IE 5.5, 6 and 7 handle character input (I am happy with the display of text). I have two main questions: 1. Does IE automaticall convert text input in HTML forms from the
3
2864
by: kvnsmnsn | last post by:
I've written the following Javascript file that includes an input text field and an output text field, the latter of which is initialized to zero. Each time the user enters a number in the input field and hits the space bar, that number gets added to the value in the output field and then the input field gets set to the empty string. The user can enter as many numbers into the input field as s/he wants. The problem I have with this is...
7
2778
by: Mary | last post by:
I have a student who has a hyphenated first name. If I concatenate the name like this: StudentName:( & ", " & ), it works as expected. If, however, I try to get the first name first by concatenating like this: StudentName: ( & " " & ), only the first name appears. I sure would appreciate any help! Mary
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.