How would I use regular expressions in Javascript?
I have the following function:
function generateUser(){
var temp = window.document.domain_form.domainname.value;
var first = temp.split("."
window.document.domain_form.login.value += first[0];
}
And I have the following code at the end of the domainname input box:
onChange="generateUser()";
Here is my problem:
I have one field called domainname, and another called login.
The user must enter a value for domainame and from this value I want to derive the login. Here are some examples of possible domain names:
mytest.com
second_test.de
stilltesting2.com
I only want the first eight characters, I don't want the .com or .de or .whatever and I don't want the http:// or the www. if they decide to write that out. If it starts with numbers (e.g. 46twenty.com) I would like to drop the numbers, and if it is only numbers (e.g. 46664.com) then I want to keep the login blank.
I have these two regular expressions that might work, but I don't know how to use them. I'm not exactly a reg expr wizz so I won't be surprised if the don't work.
Here they are:
/^(\w{,8})\.\w+$/
/^\d+(\w{,8})\.\w+$/
Please help me to get this working, any and all help is GREATLY appreciated. Thank you.
I have the following function:
function generateUser(){
var temp = window.document.domain_form.domainname.value;
var first = temp.split("."
window.document.domain_form.login.value += first[0];
}
And I have the following code at the end of the domainname input box:
onChange="generateUser()";
Here is my problem:
I have one field called domainname, and another called login.
The user must enter a value for domainame and from this value I want to derive the login. Here are some examples of possible domain names:
mytest.com
second_test.de
stilltesting2.com
I only want the first eight characters, I don't want the .com or .de or .whatever and I don't want the http:// or the www. if they decide to write that out. If it starts with numbers (e.g. 46twenty.com) I would like to drop the numbers, and if it is only numbers (e.g. 46664.com) then I want to keep the login blank.
I have these two regular expressions that might work, but I don't know how to use them. I'm not exactly a reg expr wizz so I won't be surprised if the don't work.
Here they are:
/^(\w{,8})\.\w+$/
/^\d+(\w{,8})\.\w+$/
Please help me to get this working, any and all help is GREATLY appreciated. Thank you.