I have a question, on how to validate IP:Port together.
example:
192.158.2.10:80 <--Valid
192.158.2.10 <---Invalid
So the port is a must, I found some IP validation(Regex) but to be combind with port no luck. I dont want to use a seperate input field for port.
My Idea was to like so:
var str = '192.168.10.2:80';
var substr = ':';
if (str.indexOf(substr) !== -1){
var pieces = str.split(':', 2);
var ip = pieces[0];
var port = pieces[1];
//and here validate ip and port
}else{
console.log('the char '+substr+' is not there');
}
Is this right way? or there more simple?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…