html - Javascript Regex get elements from text -
i'm quite new javascript world have no idea regex; hope can me one:
i need function gives me elements of text-block user can input through <input/
on website, can output them <input/
.
generalized input:
txt1/txt2_txt3#txt4_txt5@txt6
real input-example ("personalcode"):
user/855042,5_512125#2431072,25_729106@coursname optionaladdition
what got far html stuff , (-yep thats not much):
var base= document.getelementsbyname("personalcode")[0].value;
what need out is:
var 1 = txt1; //always letters var 2 = txt2; //always decimal number var 3 = txt3; //always decimal number var 4 = txt4; //always decimal number var 5 = txt5; //always decimal number var 6 = txt6; //can letters , decimal numbers
there never special characters such !"§$%&/()=?+*# inside text element. ö, ü, ä possible.
example:
var 1 = user; var 2 = 855042,5; var 3 = 512125; var 4 = 2431072,25; var 5 = 729106; var 6 = coursname optionaladdition;
in end want output this:
document.getelementsbyname("output-user")[0].value= one; . . .
i hope understand mean.
i hope understand right want achieve.
i made small fiddle how data. https://jsfiddle.net/zasg4zgx/6/
here code:
<form> login : <input id="logthis" type="text" name="fnname" value="user/855042,5_512125#2431072,25_729106@coursname löcher in socken flicken"> <input type="button" value="login" onclick="javascript:seperateloginstring(logthis.value)"> </form>
with id can transfer value of login field function.
function seperateloginstring(logdata) { var seperatestring = []; var temp = new string(logdata); temp = temp.replace(/@/g, ' ').replace(/_/g, ' ').replace(/#/g, ' ').replace(/\//g, ' '); seperatestring = temp.split(" "); var user = seperatestring[0]; var value1 = seperatestring[1]; var value2 = seperatestring[2]; var value3 = seperatestring[3]; var value4 = seperatestring[4]; var value5 = seperatestring[5];
with loop can add "optionaladdition" value. managed can have more 1 value
for (var = 6; < seperatestring.length; i++) { value5 += " " + seperatestring[i]; } alert(value5); }
regards,miriam
Comments
Post a Comment