I want to validate an ip address with custom format:
Format i expected :
ip address - any value - anynumber
Format above have 4 parts:
- ip address (contain a valid ip address)
- any value (contain any value)
- any number (contain only 1 to 3 digits of number)
- connecting parts (contain space,dash,space
( - )
)
Example : 213.39.59.78 - Public3 address.info - 24
function customFormat(val) {
return /^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$/.test(val);
}
var testFormat = '192.68.35.35';
document.getElementById('regex').innerHTML += testFormat + ' ' + (customFormat(testFormat) ? 'Valid Format!' : 'Invalid Format!');
<ul id="regex"></ul>
Code above used regular expression from here, but just validate the ip address.
How to validate an ip address like format i expected?