String strIP = "((1[0-9]?[0-9]?)|(25[0-5])|(2[0-4]?[0-9]?)|([3-9][0-9]?))"; strIP = strIP + "//." + strIP + "//." + strIP + "//." + strIP; p("32.47.229.222".matches(strIP));