Hello Shivani, i'm sending the message for you and flexcomponents, for
reason this topic help someone.
That class extend validator class and must be used exactly like other
validator, like this:
<com:URLValidator
id="siteValidator"
source="{tiSite}"
property="text"
required="false"/>
<mx:FormItem label="Website:" width="470">
<mx:TextInput id="tiSite" maxChars="50" width="200"/>
</mx:FormItem>
2007/11/6, shivani nayar <[EMAIL PROTECTED]>:
>
> Hi,
> thanks for replying back.
> but can u tell me how should i use this code in the mxml.
> as the textInput box is not shown with the reb border when this method is
> executed.
>
> Thanks
> Shivani
>
>
>
> ----- Original Message ----
> From: Daniel Lopes <[EMAIL PROTECTED]>
> To: [email protected]
> Sent: Monday, 5 November, 2007 8:22:33 PM
> Subject: Re: [flexcomponents] Validate URL
>
> I made this class, it is mix of 2 other classes and to many changes i
> made, but i can't remenber where i copy other classes, and this classes
> wasn't had name of authors.
> All mesages in portuguese, if you had troubles to understand, mail me.
>
> package com
> {
>
> import mx.validators. Validator;
> import mx.validators. ValidationResult ;
>
> public class URLValidator extends Validator
> {
>
> public function URLValidator( )
> {
> super();
> }
>
> public static function validateUrl( validator:URLValida tor,
> value:Object,
> baseField:String) :Array {
> var results:Array = [];
> if (results.length > 0) {
> return results;
> }
> var theStringValue: String=String( value).toLowerCa se();
> if (theStringValue. length == 0) {
> return results;
> }
> if (theStringValue. indexOf('http') == -1 && theStringValue.
> indexOf('https') == -1) {
> results.push( new ValidationResult( true,null,"NaN","Você
> precisa digitar um prefixo 'http' ou 'https' válido"));
> return results;
> }
> if (((theStringValue. indexOf('http') != -1) ||
> (theStringValue. indexOf('https') != -1)) && (theStringValue. indexOf(':')
> == -1)) {
> results.push( new ValidationResult( true,null,"NaN","Você
> precisa digitar ':' em seu website depois de 'http' ou 'https'"));
> return results;
> }
> if (((theStringValue. indexOf('http') != -1) ||
> (theStringValue. indexOf('https') != -1)) && (theStringValue. indexOf('//')
> == -1)) {
> results.push (new ValidationResult( true,null,"NaN","Você
> precisa digitar '//' em seu website depois de 'http:' ou 'https:'"));
> return results;
> }
> if ( theStringValue. indexOf('.') == -1) {
> results.push( new ValidationResult( true,null,"NaN","O
> endereço de seu website não é válido"));
> return results;
> }
> var wwwArr:Array= theStringValue. split('.');
> if (wwwArr.length < 3 && theStringValue. indexOf('www') != -1)
> {
> results.push( new ValidationResult( true,null,"NaN","Não
> existe '.' depois de 'www'"));
> return results;
> }
> var suffixDotpos: Number=theString Value.lastIndexO f(".");
> var suffixStr:String= theStringValue;
> var theSuffix:String= suffixStr.substring (suffixDotpos,
> suffixStr. length);
> if (theSuffix.length < 3 ) {
> results.push( new ValidationResult( true,null,"NaN","Seu
> sufixo de domínio é inválido."));
> return results;
> }
> return results;
> }
>
> /*private function validateIP(str: String):Boolean {
> var pattern:RegExp= /\b(25[0- 5]|2[0-4] [0-9]|[01] ?[0-9][0-
> 9]?)\.(25[ 0-5]|2[0- 4][0-9]|[ 01]?[0-9] [0-9]?)\. (25[0-5]| 2[0-4][0-
> 9]|[01]?[ 0-9][0-9] ?)\.(25[0- 5]|2[0-4] [0-9]|[01] ?[0-9][0- 9]?)\b/;
> var r:Array=pattern. exec(str) ;
> if (r == null) {
> return false;
> }
> return true;
> }*/
>
>
> override protected function doValidation( value:Object) :Array
> {
> var results:Array = super.doValidation( value);
>
> // Return if there are errors
> // or if the required property is set to false and length is 0.
> var val:String = value ? String(value) : "";
> if (results.length > 0 || ((val.length == 0) && !required))
> return results;
> else
> return URLValidator. validateUrl( this, value, null);
> }
> }
>
> }
>
>
>
>
>
> 2007/11/5, shivani nayar <cordialshivani@ yahoo.co. in<[EMAIL PROTECTED]>
> >:
> >
> > hi,
> > i need to validate a URL as a textInput in flex...
> > can anyone guide me with the same..
> >
> > Thanks in advance
> > Shivani
> >
> > ------------------------------
> > Why delete messages? Unlimited storage is just a click
> > away.<http://in.rd.yahoo.com/tagline_mail_1/*http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/>
> >
> >
>
>
> --
> Daniel Lopes - Area Criações
> www.areacriacoes. com.br <http://www.areacriacoes.com.br/>
> * * * * * * * * * * * * * * * * * * * * * * * * * * *
> 55 (31) 3077-4560 / 55 (31) 8737-7501.
> Av. Cícero Idelfonso, 50.
> João Pinheiro. CEP: 30530-000
> Belo Horizonte - MG - Brasil.
>
>
>
>
> ------------------------------
> Bring your gang together - do your thing. Start your
> group.<http://in.rd.yahoo.com/tagline_groups_2/*http://in.promos.yahoo.com/groups>
>
--
Daniel Lopes - Area Criações
www.areacriacoes.com.br
* * * * * * * * * * * * * * * * * * * * * * * * * * *
55 (31) 3077-4560 / 55 (31) 8737-7501.
Av. Cícero Idelfonso, 50.
João Pinheiro. CEP: 30530-000
Belo Horizonte - MG - Brasil.