XjSv / Diablo-3-API-PHP

Simple Diablo 3 Web API PHP Wrapper
GNU General Public License v2.0
14 stars 9 forks source link

Validate Battle.net Tag #4

Closed XjSv closed 11 years ago

XjSv commented 11 years ago

Add some regex to validate the Battle.net tag.

XjSv commented 11 years ago

BattleTags must be between 3-12 characters long. Accented characters are allowed. Numbers are allowed, but a BattleTag cannot start with a number. Mixed capitals are allowed (ex: TeRrAnMaRiNe). No spaces or symbols are allowed (“, *, #, +, etc…).

Source: http://us.battle.net/d3/en/forum/topic/6352825930#2

XjSv commented 11 years ago

Closed thanks to: Nicolas Widart (nWidart)

XjSv commented 11 years ago

Having issues matching: 가우리#3366

nicgene commented 11 years ago

I've recently been using PHP's FILTER_VALIDATE_REGEXP to create a way of validating Battle.net BattleTag's and here are my findings and working regexp.

The original posts on battle.net pointing me in the write direction: http://eu.battle.net/d3/en/forum/topic/4487360361 http://us.battle.net/d3/en/forum/topic/6352825930

Two Stack Overflow posts which got everything (that I've tested) working correctly. http://stackoverflow.com/questions/5963228/regex-for-names-with-special-characters-unicode http://stackoverflow.com/questions/4983392/matching-unicode-letter-characters-in-pcre-php

The u modifier was the last piece of the puzzle.

And the regex: "/^[\p{L}\p{Mn}][\p{L}\p{Mn}0-9]{2,11}#[0-9]{4,5}+$/u"

Tested with all the example username's from the posts above and a few others. Seems to work for my purposes. Hopefully this helps you and anybody else who comes across this.

XjSv commented 11 years ago

This seems to work. I have no yet found a case which it does not. I have modified the class thanks man.

XjSv commented 11 years ago

This is still an issue with some Battle.net Tags.

nicgene commented 11 years ago

Can you provide an example(s)? I'll work on an accurate validation.

Thanks!

XjSv commented 11 years ago

Sorry for the delay man. Its been a while and I can't seem to find the BattleTags that failed previously. Previously when I had this code live I was getting complaints that some BattleTags were returning 'No Data'. At the time it seemed like it was the RegEx validation because once i commented that code out the error stopped.

So what I will do is put this live again and monitor the logs to see for any BattleTags that fails to validate.

BeingTomGreen commented 11 years ago

Thanks @dupKey I have been using this in the wild for a short while and I have yet to see any issues so I have pushed it into my repo.

Obviously as with @XjSv's code I switched the # to a - because I replace them first.

A little off-topic do you know if Blizzard provide any reference on item ID or hero ID format? At the minute I have:

private $heroIDPattern = '/^[\d]+$/';
private $itemIDPattern = '/^[A-Za-z0-9]+$/';

Which are obviously very basic and hardly accurate..

My code is over on Bitbucket if anyone is interested. I haven't got quite as far as @XjSv (working on Auth'ed calls at the minute), but it is slightly better structured in that you don't have the same BattleTag dependency.

XjSv commented 11 years ago

Well I haven't really thought about this because the itemID and heroID will most likely come from other API requyest results. Unless Blizzard is pushing bad heroIDs and bad itemIDs then this would be a problem. However, I do not see a problem with furthering the input validation. Tightening up the application is always a good idea.

The BattleTag dependency issue is next on my list after finishing the cache functionality: https://github.com/XjSv/Diablo-3-API-PHP/issues/5

BeingTomGreen commented 11 years ago

I had the same thoughts, but then somebody asked for the ability to query based on an actual itemID (god knows how they are getting them). So I would rather have something in place than nothing hence $heroIDPattern and $itemIDPattern.

I just wondered if anyone had more information on the format of them so I could tighten up the Regexes. I have sent them an email and will let you know when they get back.

Rather than spam here I have commented on #5.

XjSv commented 11 years ago

Thank you, and yes please if you make some progress with that validation let me know. I would also like to implement it to my class.

Also I am closing this issue. If problems do arise I will open it again.