Announcement

Collapse
No announcement yet.

Searching "@" sign on input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Searching "@" sign on input

    Hello, i know this is sounds simple but to me not really..
    i wonder how can i search if the @ is present on the current string..

    ex: on input the user type [email protected]
    how to return true or false? thanks..

  • #2
    here is my code:
    result = Input.GetText("Input1");
    result = String.Find(result, "@", 1, false);

    if result == true then

    Label.SetText("Label1", "valid email");


    else
    Label.SetText("Label1", "invalid email");
    end


    it always result invalid email

    Comment


    • #3
      String.Find returns position of substring being searched for - not boolean result.
      So, change your 'if statement' accordingly. A return of '-1' indicates substring not found or error.

      Eg.
      Code:
      strImput = Input.GetText("Input1");
      strFind = String.Find(strImput, "@", 1, false);
      
      if strFind ~= -1 then
       Label.SetText("Label1", "valid email");
      else
       Label.SetText("Label1", "invalid email");
      end

      Comment


      • #4
        Search for String.Char(64)

        Comment


        • #5
          Originally posted by BioHazard View Post
          String.Find returns position of substring being searched for - not boolean result.
          So, change your 'if statement' accordingly. A return of '-1' indicates substring not found or error.

          Eg.
          Code:
          strImput = Input.GetText("Input1");
          strFind = String.Find(strImput, "@", 1, false);
          
          if strFind ~= -1 then
          Label.SetText("Label1", "valid email");
          else
          Label.SetText("Label1", "invalid email");
          end
          Thank you it works... really you are helping like me.. Thanks you are great..

          Comment


          • #6
            here is the simple pattern to match valid email adress

            Code:
            local strImput = Input.GetText("Input1");
            if (strImput:match("[A-Za-z0-9%.%%%+%-][email protected][A-Za-z0-9%.%%%+%-]+%.%w%w%w?%w?")) then
                Label.SetText("Label1", "valid email");
            else
                Label.SetText("Label1", "invalid email");
            end

            Comment


            • #7
              Thanks shabanov88 ur example also is great... thanks for share ideas

              Comment


              • #8
                Yes, regex / pattern-matching is much better option for this!
                Thanks,shabanov88 - that one's going into my code library.


                Comment


                • #9
                  And just to beat a dead horse, here's a simplified version:

                  Code:
                  local strImput = Input.GetText("Input1");
                  if (strImput:match("^[%w.][email protected]%w+%.%w+$")) then
                      Label.SetText("Label1", "valid email");
                  else
                      Label.SetText("Label1", "invalid email");
                  end

                  Comment


                  • #10
                    you guys are very good,... thanks i have many option...

                    Comment

                    Working...
                    X