473,387 Members | 1,678 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,387 software developers and data experts.

Search & Replace Function?

I have some textfield that users will enter data into on my web site
and then I'll use php and write it to mysql - for security purposes,
is there a function or way to make sure that they only enter in alpha
and numeric data?

Thanks...

Jul 16 '05 #1
4 3330
Ralph Freshour wrote:
I have some textfield that users will enter data into on my web site
and then I'll use php and write it to mysql - for security purposes,
is there a function or way to make sure that they only enter in alpha
and numeric data?

Thanks...


yes, check all the characters.
You can use a regular expression, or make your own little routine.

In case of a regex, ask somebody else. I never took the time to study them,
but know they are extremely powerfull once you get to know them.

In case of your own little routine:
just walk through the whole string and get a character at a time.
Check if the character is in a string with 'acceptable characters'

AcceptableCharacters = "abcdefghijklmnopqrstuvwxyz _1234567890-";

use strlen to get the length of any string.
use strrpos to find an occurence of any string in another string. It returns
false when not found.

use substr to get a character (or more) out of a string.

You'll have to code the rest. :-)
Good luck,
Erwin
Jul 16 '05 #2

On 16-Sep-2003, Ralph Freshour <ra***@primemail.com> wrote:
I have some textfield that users will enter data into on my web site
and then I'll use php and write it to mysql - for security purposes,
is there a function or way to make sure that they only enter in alpha
and numeric data?


if (preg_match('/[^0-9a-z]/i',$input_string))
// bad string
else
// good string

--
Tom Thackrey
www.creative-light.com
Jul 16 '05 #3
LOL,

Go follow Tom's advise. :-)

Jul 16 '05 #4

"Ralph Freshour" <ra***@primemail.com> wrote in message
news:va********************************@4ax.com...
I have some textfield that users will enter data into on my web site
and then I'll use php and write it to mysql - for security purposes,
is there a function or way to make sure that they only enter in alpha
and numeric data?

Thanks...


You could just use htmlentities() and/or htmlspecialchars() and/or
addslashes() or eregi_replace() (though the latter depends on regular
expressions and thats not the easiest to use).
Jul 16 '05 #5

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

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
10
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x";...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
1
by: Tomomichi Amano | last post by:
Hello. I want to make replace & search functions in my text editor. Thanks to the kind people here at the newsgroup, I was able to make the function. But I was not able to understand how to...
3
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
2
by: FP | last post by:
I have a javascript variable set to the contents of a database comments field. To set the js variable I used the PHP addslashes function which encodes the apostrophe, double quotes and the...
6
by: DataSmash | last post by:
Hello, I need to search and replace 4 words in a text file. Below is my attempt at it, but this code appends a copy of the text file within itself 4 times. Can someone help me out. Thanks! #...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
1
by: coolami4u | last post by:
I need a program that simulates the search-and-replace operation in a text editor. The program is to have only three function calls in main. The first function prompts the user to type a string of...
16
by: Proaccesspro | last post by:
I'm trying to create a search & replace function in Access. Specifically, I want to search for a specific SSN and replace it, if found. Not sure how to code the "guts" of it. Here is what I have...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.