473,594 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking a field for invalid chars

Hi All

Is there anyway that before I submit a form I can check the contents of an
input field to see that it only contains letters and numbers.

Thanks

Robbie
Aug 11 '05 #1
11 1544
Writing in news:alt.www.webmaster,comp.lang.javascript
From the safety of the Posted via Supernews, http://www.supernews.com
cafeteria
Astra <No@Spam.com> said:
Hi All
How do you do?
Is there anyway that before I submit a form I can check the contents of
an
input field to see that it only contains letters and numbers.


yes - usual caveats apply.

What you want is a regular expression.

--
William Tasso

** Business as usual
Aug 11 '05 #2
Astra wrote:
Is there anyway that before I submit a form I can check the contents of an
input field to see that it only contains letters and numbers.


Why did you start two threads on this subject? I've replied in the one
titled 'Stopping user from inputting anything other than letters and
numbers'.

--
Safalra (Stephen Morley)
http://www.safalra.com/programming/javascript/

Aug 11 '05 #3
Hi William

I just can't find the Reg Exp syntax for just letters and numbers, eg A-Z,
a-z and 0-9.

Do you know what it is?

Regards

Robbie
"William Tasso" <Sp*********@tb data.com> wrote in message
news:op******** ***********@tbd ata.com...
Writing in news:alt.www.webmaster,comp.lang.javascript
From the safety of the Posted via Supernews, http://www.supernews.com
cafeteria
Astra <No@Spam.com> said:
Hi All
How do you do?
Is there anyway that before I submit a form I can check the contents of
an
input field to see that it only contains letters and numbers.


yes - usual caveats apply.

What you want is a regular expression.

--
William Tasso

** Business as usual
Aug 11 '05 #4
Using a pointed stick and pebbles, Astra scraped:
I just can't find the Reg Exp syntax for just letters and numbers, eg A-Z,
a-z and 0-9.


[A-Za-z0-9]*

This will match zero or more letters and numbers. Replacing the * with a
+ will require one or more characters.

Of course, this will not match non-Latin letters or space characters
either, so you may have to fiddle with it if you require the ability to
use those.

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
Aug 11 '05 #5
Writing in news:alt.www.webmaster,comp.lang.javascript
From the safety of the cafeteria
Dylan Parry <us****@dylanpa rry.com> said:
Using a pointed stick and pebbles, Astra scraped:
I just can't find the Reg Exp syntax for just letters and numbers, eg
A-Z, a-z and 0-9.


[A-Za-z0-9]*

This will match zero or more letters and numbers. Replacing the * with a
+ will require one or more characters.

Of course, this will not match non-Latin letters or space characters
either, so you may have to fiddle with it if you require the ability to
use those.


This may assist the o/p: http://www.regular-expressions.info/

--
William Tasso

** Business as usual
Aug 11 '05 #6
Hi Dylan

I used your example in my code:

if (!([A-Za-z0-9]*.test(document .form1.fred.val ue)))
{
......
}

but it generates a syntax error.

Do you know what I've done wrong?

Rgds Robbie
"Dylan Parry" <us****@dylanpa rry.com> wrote in message
news:3m******** *****@individua l.net...
Using a pointed stick and pebbles, Astra scraped:
I just can't find the Reg Exp syntax for just letters and numbers, eg A-Z,
a-z and 0-9.


[A-Za-z0-9]*

This will match zero or more letters and numbers. Replacing the * with a
+ will require one or more characters.

Of course, this will not match non-Latin letters or space characters
either, so you may have to fiddle with it if you require the ability to
use those.

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
Aug 11 '05 #7
Using a pointed stick and pebbles, Astra scraped:

<snip code />
but it generates a syntax error.

Do you know what I've done wrong?


Try:

var re = new RegExp("^[A-Za-z0-9]*$");
if (document.form1 .fred.value.mat ch(re)) {
alert("Okay");
}
else {
alert("Not Okay");
}

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
Aug 11 '05 #8
[aww removed from follow-ups]

On 11/08/2005 13:01, Dylan Parry wrote:

[snip]
var re = new RegExp("^[A-Za-z0-9]*$");
if (document.form1 .fred.value.mat ch(re)) {


I'd prefer:

var elem = document.forms. form1.elements;

if(!/^[A-Za-z0-9]*$/.test(elem.fred .value)) {
/* Bad */
}

Or perhaps:

if(!/^[^\W_]*$/.test(...)) {
/* Bad */
}

which is the same thing.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Aug 11 '05 #9
shep loves to see invalid cars in a field

And rabbits too.
Aug 11 '05 #10

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

Similar topics

7
7568
by: - ions | last post by:
I have created a JComboBox with its Items as a list of "M" numbers ie. M1,M2,M3.......throgh too M110 (thes are the messier objects, a catolouge of deep sky objects) the user selects of of these and views it aswell as infomation. The program also has a JTextFiels which allows the user to enter the M number. The problem i have is checking that what the user has entered is valid, that being an M followed by 1 - 110 Nothing else, i thought of...
2
14272
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish to put the focus back to the offending field. ( It works if a use an 'onblur' event but not an 'onchange' )
5
3583
by: Axel | last post by:
Hi in T-SQL, (how) is it possible to concatenate 3 (varchar) fields into one; either in a SQL query or through a calculated field (or using a view, if anybody can explain to me how to use views), according to the following rules: {
2
2892
by: Xam | last post by:
Hello everybody Do you know of a javascript routine that can warn if there are any pre-defined invalid chars in the filename of an INPUT file box before it is submitted with the submit button. The process would be: a) User clicks the INPUT File's Browse button to select the file from their computer.
1
2295
by: svet | last post by:
Hello, I need to import data into integer field in Access but would like to trim the lenght of the field to 4 char. long instead of the default six char. long. This is important, because on export, I need to export the data into fixed- width format, and the length of the integers cannot be more the 4 chars long. Is there a way to change the default to 4 chars long? Although the field can be formatted to display as shorter, on export the...
2
2262
by: Gerry Abbott | last post by:
Hi all, Im using an ubound form and recordsets for data update. Id like to trap invalid entries on this form. How can i limit the number of characters the user enters for a particular field. ? Thanks in advance. Gerry Abbott
0
2288
by: William Stacey [MVP] | last post by:
Had a method that got some string info from mp3 tags in N files and serializes this class and deserializes at other side. Works ok except sometimes get chars that choke the XmlSerializer. After some digging, I found XmlSerializer chokes on 0x03 chars. It probably chokes on many others, but this one I found. It serializes ok, but chokes on deserialize on "<Field1>&#x3;</Field1>". So the questions are: 1) Why does serializer produce...
14
1516
by: tranky | last post by:
Hi, i'm italian...so...excuse me for my english. I've a little problem....in what manner i can check a textbox for know if it contain only character from A-Z (a-z), numbers (0-9), and underscore (-) and dot (.) ?!?!?!? I use vb.net. thank to all.
6
2740
by: maxx429 | last post by:
I am trying to check if notes have been added to a Memo field on a form if certain other fields have changed. Example: If the user ticks a particular check box on the form, I want to force them to add some note detailing the change before the will be allowed to save the record. I have the checks on the other fields working. What I can't seem to find an effective method for is checking whether the user has added notes to the Memo field on the...
0
7937
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
7874
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8244
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
6647
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...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5403
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3854
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...
1
1471
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1204
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.