Hi guys, i am trying to sieve out the username and text fields of a HTML Form loading in a web view. Previously i tried this method to narrow down the corresponding text fields that i need but it was tedious and there is no end to the computation of variables. even though i thought i listed out a lot of variables, it was still a hit and miss solution, not all website works.
Then i was told about RegularExpression but i wasn't very familiar with it and i read some tutorials about it but not specific to my project to try and get what it means and i piece out this code which is also a hit and miss solution. I am not even sure if i am doing it right but the code is definitely short this time for sure.
Can someone tell me if i have done this RegularExpression correctly? i really have no idea. Some sites it works, some it doesn't.
Code:
NSString *loadUsrText = [NSString stringWithFormat:@"var inputFields = document.querySelectorAll(\"input[type='text']\"); \
for (var i = inputFields.length >>> 0; i--;) { \
if ( (inputFields[i].getAttribute('name') == 'email') || (inputFields[i].getAttribute('name') == 'Email') || (inputFields[i].getAttribute('name') == 'e-mail') || (inputFields[i].getAttribute('name') == 'E-mail') || (inputFields[i].getAttribute('name') == 'emailerr') || (inputFields[i].getAttribute('name') == 'UID') || (inputFields[i].getAttribute('name') == 'uid') || (inputFields[i].getAttribute('name') == 'username') || (inputFields[i].getAttribute('name') == 'Username') || (inputFields[i].getAttribute('name') == 'userName') || (inputFields[i].getAttribute('name') == 'user_name') || (inputFields[i].getAttribute('name') == 'User_Name') || (inputFields[i].getAttribute('name') == 'User_name') || (inputFields[i].getAttribute('name') == 'userid') || (inputFields[i].getAttribute('name') == 'userID') || (inputFields[i].getAttribute('name') == 'UserID') || (inputFields[i].getAttribute('name') == 'Userid') || (inputFields[i].getAttribute('name') == 'ID') || (inputFields[i].getAttribute('name') == 'id') || (inputFields[i].getAttribute('name') == 'j_username') || (inputFields[i].getAttribute('name') == 'session_key') || (inputFields[i].getAttribute('name') == 'login_password') || (inputFields[i].getAttribute('name') == 'liveid') || (inputFields[i].getAttribute('name') == 'Liveid') || (inputFields[i].getAttribute('name') == 'liveID') || (inputFields[i].getAttribute('name') == 'LiveID') || (inputFields[i].getAttribute('name') == 'liveID') || (inputFields[i].getAttribute('name') == 'LiveID') || (inputFields[i].getAttribute('name') == 'live_id') || (inputFields[i].getAttribute('name') == 'Live_id') || (inputFields[i].getAttribute('name') == 'live_ID') || (inputFields[i].getAttribute('name') == 'Live_ID') || (inputFields[i].getAttribute('name') == 'Live') || (inputFields[i].getAttribute('name') == 'live') || (inputFields[i].getAttribute('name') == 'live_email') || (inputFields[i].getAttribute('name') == 'Live_email') || (inputFields[i].getAttribute('name') == 'Live_Email')){ \
inputFields[i].value = '%@';}}", myUsername];
[self.myWebView stringByEvaluatingJavaScriptFromString: loadUsrText];
Then i was told about RegularExpression but i wasn't very familiar with it and i read some tutorials about it but not specific to my project to try and get what it means and i piece out this code which is also a hit and miss solution. I am not even sure if i am doing it right but the code is definitely short this time for sure.
Code:
NSString *loadUsrText = [NSString stringWithFormat:@"var inputFields = document.querySelectorAll(\"input[type='text']\"); \
for (var i = inputFields.length >>> 0; i--;) { \
regStr = /(mail|user|iden|name|id|key|login|username|email)/i; \
searchName = inputFields[i].getAttribute('name').search(regStr);\
searchId = inputFields[i].getAttribute('id').search(regStr);\
if (!(searchName == -1) || !(searchId == -1)){ \
inputFields[i].value = '%@';}}", myUsername];
[self.myWebView stringByEvaluatingJavaScriptFromString: loadUsrText];
Can someone tell me if i have done this RegularExpression correctly? i really have no idea. Some sites it works, some it doesn't.