URL validation with struts??

perfectobject
perfectobject used Ask the Experts™
on
Hello Experts,

how to validate the URL using struts validation framework..!!

i have used following code,but it is not allowing the URL's of any format.

                <field property="url" depends="required,url">
                
                    <arg0 key="UserRegForm.url"/>
                    
               </field>

Thanks..!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
hi gurvinder,

thanks for your comment....i have implemeted the same thing ....it is not allowing the URL's of any format(eg:www.google.com,google.co.in...etc)
can you post the code where you have implemented it using the link that i have posted?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Author

Commented:
ok....this is my validation.xml code:

                <field property="url" depends="required,url">
               
                    <arg0 key="UserRegForm.url"/>
                   
               </field>

config file:

<form-bean name="UserRegForm" type="org.apache.struts.validator.DynaValidatorForm">

<form-property name="url" type="java.lang.String" />

</form-bean>

and this is my from:

                                      <tr>
                                            <td><font size="3" color="white" face="Tahoma">URL:</font></td>
                                            <td><html:text property="url"/></td>
                                      </tr>
can you try this one?

<validators>

  <field name="url">
    <field-validator type="url">
       <message>Please enter a valid url</message>
    </field-validator>
  </field>

</validators>


or this one,

 <field property="custUrl" depends="url">
        <arg0 key="customer.url"/>
        <var>
           <var-name>nofragments</var-name>
           <var-value>true</var-value>
        </var>
        <var>
           <var-name>schemes</var-name>
           <var-value>http,https,telnet,file</var-value>
        </var>
    </field>

Author

Commented:
2nd code sample is not working.....where i have to put the 1st code sample..!!
first code sample goes in the validation.xml file
please check this link for reference
http://www.roseindia.net/struts/struts_validator_framework.shtml

Author

Commented:
1st code sample also not working..!!
can you try with a difference name than 'url'?
Thanks
Also please let me know what code did you wrote for the first sample. Thanks
Please check if your form bean class is extending ValidatorForm
see this
http://www.laliluna.de/struts-form-validation-error-handling.html

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial