javascript - \s RegEx not capturing new line data -
javascript - \s RegEx not capturing new line data -
i trying clean input , set desired way. basically, have serialnumbers entered several different ways - come in delimited (newline), space, comma, etc.
my problem in code below in testing new line delimited isn't working. according w3schools , 2 other sites: \s metacharacter used find whitespace character. whitespace character can be: -a space character -a tab character -a carriage homecoming character -a new line character -a vertical tab character -a form feed character
this should mean can grab new line. in netsuite, user entering value as: sn1sn2sn3 i want alter "sn1,sn2,sn3,". \s regex not picking newline? help appreciated.
**for record - while using netsuite (crm) input, rest of code typical javascript , regex work. why using 3 tags - netsuite, js, , regex
function fixserailnumberstring(s_serialnum){ var cleanstring = ''; var regexspace = new regexp('\\s',"g"); if(regexspace.test(s_serialnum)){ var a_splitsn = s_serialnum.split(regexspace); for(var = 0; < a_splitsn.length;i++){ if(a_splitsn[i].length!=0){ cleanstring = cleanstring + a_splitsn[i]+((a_splitsn[i].split(',').length>1)?'':','); } } homecoming cleanstring; } else{ alert("no cleaning needed"); homecoming s_serialnum; } }
edits: 1-i need handle both if has spaces (such "sn1, sn2, sn3" needs become "sn1,sn2,sn3") , newline issue. have above works spaces. 2- not sure if matters, field textarea. impact this?
@cheery found why happening. said, got info netsuite , using api data. in ui of netsuite info did each line on new line, however, when doing console.log values not.
example: ui displayed: sn1 sn2 sn3
console.log displayed: sn1sn2sn3
i assuming ui translated actual value , didn't think check string was.
javascript regex netsuite
Comments
Post a Comment