473,789 Members | 2,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ANSI C: How to validate input string using regular expression?

121 New Member
Hello everyone.

This question is regarding ISBN number checking. I've done it with my own algorithm, which is pretty bad in consideration about the total lines of code.

Now I want to improve it, I guess the best practice wold be using regular expression to handle this string validation:

Say, I've got the user input string with fgets(array, 20, stdin);

If it is a valid ISBN number, then it must have a valid format:
- the valid char set is:"0123456789 X- \n"
- there must be exactly 10 "digit" chars, which are in this set "0123456789 X"
- char 'X' must either not exist or at the last position of the digits.
...

It's about the content checking, I don't know how to apply the logic into the code.

Thanks in advance!




Sincerely yours,

Matt
Sep 19 '07 #1
3 7284
gpraghuram
1,275 Recognized Expert Top Contributor
Hello everyone.

This question is regarding ISBN number checking. I've done it with my own algorithm, which is pretty bad in consideration about the total lines of code.

Now I want to improve it, I guess the best practice wold be using regular expression to handle this string validation:

Say, I've got the user input string with fgets(array, 20, stdin);

If it is a valid ISBN number, then it must have a valid format:
- the valid char set is:"0123456789 X- \n"
- there must be exactly 10 "digit" chars, which are in this set "0123456789 X"
- char 'X' must either not exist or at the last position of the digits.
...

It's about the content checking, I don't know how to apply the logic into the code.

Thanks in advance!




Sincerely yours,

Matt


Hi,
I cant get what you mean by "cant apply the logic to your code"
R u facing any issues with the logic or with coding?
Please be more specific abt the help u need and we can help you out

Thanks
Raghuram
Sep 19 '07 #2
mattmao
121 New Member
Sorry for that.

Here are my puzzles:

First, it seems that the ANSI C doesn't have a regular expression lib. I've checked with all the .h file lists...

Second, say if I get the regular expression exp=[0-9]{10}; how to use it to check against the user input string?

I can solve this kind of problem using JavaScript because JavaScript can use regular expression to validate the input string, but I don't know how to do that in ANSI C.




Sincerely yours,

Matt
Sep 19 '07 #3
JosAH
11,448 Recognized Expert MVP
There is no regular expression facility available in the ANSI standard library but
there are several libraries available that do implement this facility; google for
'regular expression ANSI C' and see which one you like most.

If you can't find anything you might google for 'Henry Spencer regular expression'.
Henry is one of the regular expression gurus and largely defined what POSIX
compliant regexes should look like.

kind regards,

Jos
Sep 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

13
4812
by: Eddie | last post by:
I need to validate a text input field. I just want to say if user enters 93101 or 93102 or 93103 or 93105 or 93106 or 93107 or 93108 or 93109 or 93110 or 93111 or 93116 or 93117 or 93118 or 93120 or 93121 or 93130 or 93140 or 93150 or 93160 or 93190 or 93199 or 93199 or 93401 or 93402 or 93403 or 93405 or 93406 or 93407 or 93408 or 93409 or 93410 or 93412
32
14902
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
7
25382
by: Chris Kennedy | last post by:
Does anyone know a regular expression that will validate the file extension but also allow multiple file extensions if necessary. It also needs to be case insensitive. Basically, what I want is to validate a file input box to check if the extension is the correct type, i.e. .doc for a Word Document etc. Also I would like to check multiple file types, for instance allow a gif or a jpeg or a jpg. Regards, Chris.
6
7167
by: Friso Wiskerke | last post by:
Hi All, I'm trying to find a way to validate a string variable in the code behind with a regular expression. I know there are validator controls but these all work with the ControlToValidate property and I don't have a control, just a string variable. Can anyone help me out? TIA,
10
3203
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from the output, save for those that manage color codes or text presentation (in short, the ones that are ESChttp://fd0man.theunixplace.com/Tmud.tar which contains the code in question. In short, the information is coming in over a TCP/IP socket that...
6
8377
by: =?Utf-8?B?ZGlhdG9tQG5ld3Nncm91cC5ub3NwYW0=?= | last post by:
Hello, I have a data entry windows form. One of the text boxes allows the user to enter a string. I need this text box to only allow users to type in a negative integer value (e.g. -1, -2, -3). Current approach: I want to validate the user's entry during the TextChanged() event. During the validation, I need a function that will parse the string and see if it is a negative integer. Does anyone have suggestions on the best way to...
5
1873
by: Ganesh | last post by:
Hi There, I need to validate email address with regular expression control, i tried something like this ^+*@*\.*$ but i need to validate even if it is blank, it should say invalid email, but don't want to use another requirefield validator
7
2242
by: Amit | last post by:
Dear Friends I need to write a Java Script for a string payment_code which comes populated from a text field , should contain only 0-9,A-Z,a-z,Space ' ',Hyphen '-',Full stop '.',Comma ',',Plus '+' Characters other than these will not be allowed If a user enters characters other than the mentioned above , the alert message should be displayed
5
13849
by: shapper | last post by:
Hello, What is the Regex expression to validate a date time format as follows: dd-mm-yyyy hh:mm:ss An example: 20-10-2008 10:32:45
0
9666
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
9511
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
10410
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...
1
10139
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
9984
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...
1
7529
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
6769
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();...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
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.