Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Regular expressions for form elements

Last post 10-05-2008, 2:49 PM by mash. 6 replies.
Sort Posts: Previous Next
  •  10-04-2008, 4:51 AM 46873

    Regular expressions for form elements

    Hi all,

    I am new in learning regular expressions and I need a little bit help.

     

    How do I match input type elements from a site.

    I need to match all and in case that type of input is text (type="text"), I have to check if value attribute exists .

    The type could be in every possible position in the element such as <input type="text" value="Login" ...> or <InPut value="Password" type="text" ...> 

     If exists input element and every input element have value print --> OK

    In other case , print --> input element does not have value attribue 

    else print --> I did;t find input element.

     

    And something finally, I would like to check also textareas.

    The different is that I have to check if text exists between <textarea ...> and </textarea>

     

     

     

     

  •  10-04-2008, 5:08 AM 46874 in reply to 46873

    Re: Regular expressions for form elements

    katerina90:

    Hi all,

    I am new in learning regular expressions and I need a little bit help.

     

    How do I match input type elements from a site.

    I need to match all and in case that type of input is text (type="text"), I have to check if value attribute exists .

    The type could be in every possible position in the element such as <input type="text" value="Login" ...> or <InPut value="Password" type="text" ...> 

     If exists input element and every input element have value print --> OK

    In other case , print --> input element does not have value attribue 

    else print --> I did;t find input element.



    This regex will matche an input tag containing 'type="text"':

    (?i)<input[^>]*type="text"[^>]*>




    katerina90:

    And something finally, I would like to check also textareas.

    The different is that I have to check if text exists between <textarea ...> and </textarea>

     



    Not sure what you mean by "if text exists", but you can probably use the regex I posted to solve this.

  •  10-04-2008, 5:51 AM 46875 in reply to 46874

    Re: Regular expressions for form elements

    prometheuzz:
    katerina90:

    Hi all,

    I am new in learning regular expressions and I need a little bit help.

     

    How do I match input type elements from a site.

    I need to match all and in case that type of input is text (type="text"), I have to check if value attribute exists .

    The type could be in every possible position in the element such as <input type="text" value="Login" ...> or <InPut value="Password" type="text" ...> 

     If exists input element and every input element have value print --> OK

    In other case , print --> input element does not have value attribue 

    else print --> I did;t find input element.



    This regex will matche an input tag containing 'type="text"':

    (?i)<input[^>]*type="text"[^>]*>


    I need to check also if exists value attribute in this input element.

    Could you help me ?

    prometheuzz:

    katerina90:

    And something finally, I would like to check also textareas.

    The different is that I have to check if text exists between <textarea ...> and </textarea>

     



    Not sure what you mean by "if text exists", but you can probably use the regex I posted to solve this.

     

    I mean that :

    case 1 <textarea cols="2" row="2">Hello</textarea>

    case 2 <textarea cols="2" row="2">&nbsp;</textarea>

    case 3 <textarea cols="2" row="2"></textarea>

     

    Case 1 is right use , while case 2 and 3 are wrong.  

  •  10-04-2008, 7:42 AM 46877 in reply to 46875

    Re: Regular expressions for form elements

    Somebody ??
  •  10-04-2008, 7:54 AM 46878 in reply to 46877

    Re: Regular expressions for form elements

    katerina90:
    Somebody ??

    I don't like helping people who are impatient.

    Good luck.

  •  10-04-2008, 8:17 AM 46879 in reply to 46878

    Re: Regular expressions for form elements

    as you wish
  •  10-05-2008, 2:49 PM 46897 in reply to 46879

    Re: Regular expressions for form elements

    As I advise most, you are most likely better served using the HTML DOM to parse HTML, rather than a regex.  It is very easy create vaild HTML that will break a given regex patten.

    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
View as RSS news feed in XML