473,394 Members | 1,865 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.

validates characters

Hey all

i would like to know if someone can please help me.
i would like to know how to validate characters so that the user would not
be able to enter numbers into a characters field.

thanx
Jul 22 '05 #1
6 1174
On Wed, 28 Jul 2004 09:20:52 +0200, Lyle Ladeira <la******@mweb.co.za>
wrote:
Hey all

i would like to know if someone can please help me.
i would like to know how to validate characters so that the user would
not
be able to enter numbers into a characters field.

thanx


Well first you have to define what you want. What do you mean by number?

123 - this is a number, so it isn't valid, right?

12ab - is this valid or not? its not a number but it does have numbers in
it

12.3 - what about this?

-123 - what about this?

So I think you need to specify exactly what input is valid and what is
not, then someone will be able to help.

John
Jul 22 '05 #2
hey

the only thing that should be valid is letters and spaces
A-Z a-z and spaces, tabes etc...

thanx
Jul 22 '05 #3
Lyle Ladeira writes:
i would like to know if someone can please help me.
i would like to know how to validate characters so that the user would not
be able to enter numbers into a characters field.


The way that is usually recommended is to get the entire line, perhaps using
getline(), see if a suitable number is in the line, and then do your own
conversion. The easiest way is probably to use <cstdlib> functions such as
strtod() and strtol(); although you can do this with "pure" C++ techniques
too. If you find a nice number, go on. Otherwise ask the user to reenter
the entire line.

A second way is to read as though you expect the user to do a proper entry
and then clear up the mess created in the stream if he doesn't. You must
clear the fail state and empty the buffer, in *that order*. see
ios::clear() and istream::ignore(). Then ask the user to try again.

The first way is probably easier and you may learn more of long term
interest that way, too.

Jul 22 '05 #4

"Lyle Ladeira" <la******@mweb.co.za> wrote in message
news:ce**********@ctb-nnrp2.saix.net...
hey

the only thing that should be valid is letters and spaces
A-Z a-z and spaces, tabes etc...

thanx


OK, the way to do this is to loop through all the characters of the string
testing each one. As soon as you find an invalid character then you know
that the whole string is invalid. If you don't find an invalid character
then the string is valid. Something like this

#include <ctype.h>

bool is_valid(const char* str)
{
while (*str)
{
if (!isalpha(*str) && !isspace(*str)) // if not alphabetic and not a
space ...
return false; // .. then its not valid
++str;
}
return true; // all chars tested ok so its valid
}

john
Jul 22 '05 #5
Thanx alot guys it works
Jul 22 '05 #6
Lyle Ladeira wrote:
Hey all

i would like to know if someone can please help me.
i would like to know how to validate characters so that the user would not
be able to enter numbers into a characters field.


You may use <cctype> facilities, like isalpha(), isdigit() etc.


Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #7

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

Similar topics

1
by: Kapten Haddock | last post by:
Hi. I have a simple schema which validates fine in XML Spy but in .Net I get a Type Exception: The effect I'm looking for is to be able to pass an empty date. The Schema File: <?xml...
1
by: Martin Z | last post by:
I'm getting acquainted with the whole XML/XSD thing, and I've run into a wall. I have a tree of objects that I deserialize from XML for configuration reasons. I have generated XSD from the...
6
by: yaru22 | last post by:
I'd like to create a program that validates bunch of urls against the w3c markup validator (http://validator.w3.org/) and store the result in a file. Since I don't know network programming, I...
2
by: Jake Barnes | last post by:
Please check out this page: http://www.bluewallllc.com/Laura/cms/index.php?pageId=2217 It validates, and it is rendering about right in FireFox. However, in IE it has a bunch of extra padding...
0
by: draconas | last post by:
Hi all As part of a project I have a vb program that takes an XML document (payload-XML), which contains a lot of data, but no namespaces. It is run through an XSLT transformation which creates...
4
by: rdfijn | last post by:
I tried to combine some stuff from Eric Meyer and Stu Nicholls to create a webpage layout. First try: http://www.dse.nl/~rodney/index.html It validates, but for some reason in IE7 only a...
8
by: dmorand | last post by:
Ok, I'd like your suggestions. I have a field on my page which is password protected. If the user clicks the link and validates the password, I'd like to have the comments display. Does anyone...
1
by: postmanpat | last post by:
i have to create a login form that validates the users and passwords from a text file. I have another function that can add new users and passwords by writing to a test file split by a delimiter. But...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, I have a WinForms with two buttons: AcceptButton, CancelButton and several textbox. I want to validate some textboxes, and I set Validating event for them. I want not validates...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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...
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
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...

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.