PDA

View Full Version : remove non alphanumeric chars + output last 6 chars



ZxIRAX
05-29-2009, 08:30 AM
I am looking for some help creating a script, ideally in JS if this is possible.

Essentially the end user will paste a string of characters (varying in length anything from 11-18 characters) into a text box, then click a button which will remove any non alphanumeric characters and spaces and display the last 6 digits of the string.

For example, the user pastes: 7/9684798- 3
The output should be: 847983

Any help would be great!

vwphillips
05-29-2009, 02:20 PM
var N='7/9684798- 3';
N=N.replace(/\D/g,'');
alert(N.substring(N.length-6));