Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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

  • #2
    New to the CF scene
    Join Date
    Jul 2002
    Location
    Novosibirsk, Russia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    $data1 =~ s/[^ 0-9A-Za-z]//g;
    $data2 =~ s/[^ 0-9A-Za-z]//g;
    $data3 =~ s/[^ 0-9A-Za-z]//g;
    $data5 =~ s/[^0-9A-Za-z]//g;
    $data6 =~ s/[^0-9]//g;
    The last one will only do what you asked, that is, it will also change "2.5+3.7=6.2" into "2.53.76.2".

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #4
    New Coder
    Join Date
    Jul 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #5
    New to the CF scene
    Join Date
    Jul 2002
    Location
    Novosibirsk, Russia
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Get the manual and read the perlre part. Understanding regular expressions is essential for text analysis.
    Code:
    &hellip; || $FORM{'data8'} !~ /^[0-9A-Za-z]*$/ || &hellip;
    This subexpression evaluates to true if $FORM{'data8'} does not match (!~) the regular expression /^[0-9A-Za-z]*$/, which means:
    • ^ &mdash; start of text,
    • [0-9A-Za-z] &mdash; digit or letter,
    • * &mdash; repeated 0 or more times,
    • $ &mdash; end of text.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •