I want to include unicode characters (to be more specific, Tamil words) in the 'name' of my Code Igniter cart. I found this example. I tried the following, so that the regex could match anything:
$this->cart->product_name_rules = '.+';
$this->cart->product_name_rules = '.*';
$this->cart->product_name_rules = '.';
But for all these, I get the error "An invalid name was submitted as the product name: சும்மாவா சொன்னாங்க பெரியவங்க The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces" in my log.
Also, thinking it could be due to unicode support, I tried the following:
$this->cart->product_name_rules = '\p{Tamil}';
But to no avail. Can you please point if something wrong here?
Try adding each Tamil character individually to your regex. I had to do this for special characters in input keys:
if ( ! preg_match("/^[a-z0-9àÀâÂäÄáÁãÃéÉèÈêÊëËìÌîÎïÏòÒôÔöÖõÕùÙûÛüÜçÇ’ñÑß¡¿œŒæÆåÅøØö:_\.\-\/-\\\,]+$/i", $str))
{
exit('Disallowed Key Characters.');
}
Here he posted how did he managed to save the cyrilic character in Codeigniter 1.7.2's cart.
Related
I have got a pattern to validate a HTML5 email field:
[A-z\u00c0-\u017e0-9._%+-]+#[A-z\u00c0-\u017e0-9.-]+\.[A-z]{2,3}$
It should allow European characters as well as numbers and other symbols.
I am getting this error:
A part followed by '#' should not contain the symbol 'á'
It allows abc#défg.com but not ábc#defg.com
Is anyone able to help? Thanks!
I´m using the following code to generate urls:
url(r'^productos/(?P<person_id>\D+)/$', views.ProductoView, name="producto"),
It works fine with strings that only have letters (dTape).
When I try a string that includes a number (d3Tape) I get a nonreverse error.
Any clues? Maybe my regex is not ok but I can´t find the solution.
Thanks!
You can include all characters by using a character group that includes both \d and \D:
url(r'^productos/(?P<person_id>[\d\D]+)/$', views.ProductoView, name="producto"),
But I'm not sure if this is a good idea. It might be useful to restrict the caracters to a group, like:
url(r'^productos/(?P<person_id>[A-Za-z0-9_-]+)/$', views.ProductoView, name="producto"),
this will include all ASCII alphanumerical characters and a hyphen and underscore.
In django-2.x, I would advise to use the str, or slug path converters:
path('productos/<str:person_id>/', views.ProductoView, name="producto"),
I try to get an URL from a String of the following format:
RANDOMRUBBISHhttps://www.my-url.com/randomfirstname_randomlastnameRANDOMRUBBISH
I already tried some things, especially the the look before/after, which I used before successfully on another url format (starts https... ends .html, this was working).
But seems I'm too stupid to figure out the regex for the kind of string mentioned above. I just want the URL part from https.... to the end of the random last name. Is this even possible?
Any Ideas?
If you can guarantee that randomfirstname_randomlastname is all lowercase and RANDOMRUBBISH is all uppercase, you can use character classes [a-z] and [A-Z]. The language the regex is for will determine how to use these.
This is example works in javascript:
var str = "RANDOMRUBBISHhttps://www.my-url.com/randomfirstname_randomlastnameRANDOMRUBBISH";
var match = /https:\/\/www\.my-url\.com\/[a-z]*/.exec(str);
I need to validate alphabetical characters in a text field. What I have now works fine, but there is a catch, I need to allow accented characters (like āēīūčļ) and on a Latvian keyboard these are obtained by typing the singlequote first ('c -> č), so my validator fails is the user types the singlequote and a disallowed character like a number, obtaining '1.
I have this coffeescript-flavor jQuery webpage text entry field validator that only allows alphabetical characters (for entering a name).
allowAlphabeticalEntriesOnly = (target) ->
target.keypress (e) ->
regex = new RegExp("[a-zA-Z]")
str = String.fromCharCode((if not e.charCode then e.which else e.charCode))
return true if regex.test(str)
e.preventDefault()
false
And it gets called with:
allowAlphabeticalEntriesOnly $("#user_name_text")
The code and regex work fine, denying input of most everything except small and large letters and the singlequote, where things get tricky.
Is there a way to allow accented characters with the singlequote layout, but deny entry of forbidden characters after the quote?
EDIT: If all else fails, one can implement back-end invalid character deletion a-la .gsub(/[^a-zA-Z\u00C0-\u017F]/, ''), which is what I ended up doing
Try using [a-zA-Z\u00C0-\u017F] to match a-z and accented characters (all characters within unicode range specified).
See: Matching accented characters with Javascript regexes
I'm trying to use a regex validator on a zend form element like this-
$textarea = $this->createElement('text','scores');
$textarea->setLabel('Enter a comma separated list of numbers');
$textarea->setDecorators(
array('ViewHelper',
array('HtmlTag',
array('tag' => 'div',
'class'=>'scores'
)
)
)
);
$textarea->addDecorator('Label')
->setRequired(true)
->addFilter(new Zend_Filter_StringTrim())
->addValidator('regex',true,array('^\d{1,3}([,]\d{1,3})*$'))
->addErrorMessage('Please enter a comma separated list of numbers');
I'm just trying to validate that the text area contains a list of comma separated numbers.
Currently im getting "Internal error while using the pattern '^\d{1,3}([,]\d{1,3})*$'".
I guess there's something wrong with the regex?
Any help would be appreciated :)
thanks,
pete
Try escaping the backslashes:
'^\\d{1,3}(,\\d{1,3})*$'
You don't need the brackets around the comma.
Also, you might want to allow whitespace between the numbers and separators:
'^\\s*\\d{1,3}(\\s*,\\s*\\d{1,3})*\\s*$'
You need add symbols for start and end regexp. For example:
->addValidator('regex',true,array('#^\\d{1,3}([,]\\d{1,3})*$#'))
true you need delimiters. but don't escape your slashes :)
IMHO you are missing slash "/" at the end of your regex. I'm not an expert but this is working for me:
->addValidator(new Zend_Validate_Regex('/^[a-zA-Z0-9][a-zA-Z0-9 ._-]{1,31}/'));