473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1533
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*********@tbdata.com> wrote in message
news:op*******************@tbdata.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****@dylanparry.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.value)))
{
......
}

but it generates a syntax error.

Do you know what I've done wrong?

Rgds Robbie
"Dylan Parry" <us****@dylanparry.com> wrote in message
news:3m*************@individual.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.match(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.match(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
Michael Winter wrote
[aww removed from follow-ups]


Why, are we not worthy?

--
Charles Sweeney
http://CharlesSweeney.com
Aug 11 '05 #11
Astra wrote:
Hi Dylan

I used your example in my code:

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

but it generates a syntax error.

Do you know what I've done wrong?


if (!/[a-z0-9]+/i.test(document.form1.fred.value))

Mick
Aug 11 '05 #12

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

Similar topics

7
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...
2
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...
5
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...
2
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. ...
1
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...
2
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. ? ...
0
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...
14
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...

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.