![]() |
Cleaning form submited strings
Hi Friends,
I need a method for cleaning strings from all NON alphabetic and numeric characters that are submitted by a form I have the following strings: $data1 - $data2 and $data3 before writing these 3 strings to file, I want to eleminate all characters that are not a-z, A-Z and 0 to 9 and replace them with nothing, not even a blank. Meaning if $data1 = "my tel # 025/123.895.548" should become $data1 = "my tel 025123895548" Then I need the same as above but also eleminating blank spaces such as: $data5 = "map &125 #abc <small" becomes $data5 = "map25abcsmall" And to make things even worse I need a very difficult one That eleminates everything that is not a number or a decimal point. $data6 = "Temperature for city $manoi <b>40.08</b> celcius" becomes $data6 = "40.08" Best Regards, Sanuk |
Code:
$data1 =~ s/[^ 0-9A-Za-z]//g; |
Thanks
Hi,
Thanks alot Centaur. I will try it out tomorrow and let you know if it works (for sure it will). I am of to sleep now, it is here 2 AM in the morning. Thanks Centaur and Regards, Sanuk:thumbsup: |
More Questions
Hi friends,
Thanks, it works !! But now I need just the opposite for a fill-in form. ==================== $minchar = '10'; $maxchar = '20'; if(length $FORM{'data8'} < $minchar || length $FORM{'data8'} > $maxchar) { &errormessage } ======================== 1/How do I add to the above that the string may ONLY contain letters a-z and A-Z and/or numbers 0-9, nothing else. 2/completely same as above, but may also not contain any spaces. Thanks and Regards, Sanuk |
Get the manual and read the perlre part. Understanding regular expressions is essential for text analysis.
Code:
… || $FORM{'data8'} !~ /^[0-9A-Za-z]*$/ || …
|
| All times are GMT +1. The time now is 09:43 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.