[java] validare IP e domain con le regex
Posted by 0m4r on 27-08-2003 16:16
ho fatto un copia incolla del mio post sul forum della sun, non avevo molta voglia di tradurre, tanto si capisce il problema...no?

Non sono nemmeno tanto sicuro di avere fatto le regexp giuste, se notate qualche errore me lo dite?


this is the code I use but I can't set EXP2 to limit the number under the 256. Does anybody help?

P.S.
EXP1 validate a domain name (es. www.myserver.com)
EXP2 may validate IP address (es. 111.111.111.0)

code:
public static boolean isServerAddress(String s){ System.out.print(s + " "); String EXP1 ="([a-zA-Z0-9]+).([a-zA-Z0-9]+).([a-zA-Z]{2,3})|([a-zA-Z0-9]+).([a-zA-Z0-9]+).([a-zA-Z]{2,3}).([a-zA-Z]{2,3}+)"; String EXP2 ="([0-9]{1,3}+).([0-9]{1,3}+).([0-9]{1,3}+).([0-9]{1,3})"; if(Pattern.matches(EXP1, s)){ return true; }else if(Pattern.matches(EXP2, s)){ return true; }else{ return false; } }



Powered by: vbHome (lite) v3.8 and vBulletin v2.3.1
Copyright © 2000 - 2002 Jelsoft Enterprises Limited