46
rated 0 times
[
47]
[
1]
/ answers: 1 / hits: 18881
/ 11 Years ago, thu, may 30, 2013, 12:00:00
I have a dynamic string like this which may look like:
69.43.202.97 OR ngs.pradhi.com
I want to validate these string contains only numbers, english alphabets and . . I want to validate this in front end using java script. I thought of using regular expression like this:
function validatePath() {
var path = document.getElementById('server_path').value;
path.match([a-z][0-9]) //or something like this
}
If the path is invalid despite of displaying the alert box I just want to show the error below the text field as soon as the user fills the server path. How can I do that?
My full javascript function looks like this:
function validatePath() {
var path = document.getElementById('server_path').value;
if (path.search(:) == -1){
alert(Invalid server path);
}
else{
var host_name = path.split(:)[0]
if host_name.match(^[a-zA-Z0-9.]*$)) {}
}
}
More From » validation