Well the /\D/g bit is a regular expression. In RegExp's, rather than double quotes, forward slashes are used to contain them, this is to distinguish them from strings.
The \D bit is the RegExp symbol for a non-number, so the whole RegExp is just a non-number, the g at the end just tells it to search every character in the string that it is applied to. So in this case it will check all characters in the sting to see wherether they are non-numbers.
checks the first character to see whether it is an a, if it is it will replace it with a b, so:
will check every character to see if they are non-numbers, if they are it replaces them with b, in this one:
if it finds a non-number, it removes it but doesn't replace it with anything.
There is sometimes a way to shorten if/else statements and I have used one here:
The if/else version of that would be this:
This shortend version can only be used for if you are applying a value to a variable. You can also do things with it like:
That just saves time, creating the variable, applying a value to it and then calling the variable later on.
The !tel bit checks to see if tel has a null value, ie: all variables the do not exist have a null value, and so does the variable tel if the cancel button of the prompt box is pressed, this is because no value is applied to the variable.
The symbol != means not equal to, I have used it here:
the ! symbol is very useful for reversing meanings, I tend to think of it as "not".
Well I bet you never thought that such a little bit of code would need so much explaining, I guess that's why I was able to shorten your code so much, because most of it is contained in that one line.