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:URLValidator,
value:Object,
baseField:String):Array {
var results:Array = [];
if (results.length > 0) {
return results;
}
var theStringValue:String=String(value).toLowerCase();
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=theStringValue.lastIndexOf(".");
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 <[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
* * * * * * * * * * * * * * * * * * * * * * * * * * *
55 (31) 3077-4560 / 55 (31) 8737-7501.
Av. Cícero Idelfonso, 50.
João Pinheiro. CEP: 30530-000
Belo Horizonte - MG - Brasil.