GNOME Bugzilla – Bug 446056
allow filtering GtkEntry input with regular expressions
Last modified: 2011-02-23 01:30:13 UTC
Hi!, I'm attaching a patch to make GtkEntry able to filter text input based on a GRegex
Created attachment 89697 [details] [review] patch to add regexp-based filtering
Created attachment 89699 [details] test application It only allows to enter IPv4 addresses in the entry
Like the feature. Thanks for implementing it. Though can you explain a bit how it works? What happens if, say, you try to edit the text content in the middle as opposed to the end?
I've used g_match_info_is_partial_match() to implement the feature, so any edition to the entry that leaves a partial match is allowed, but when there is no possibility of matching the regex pattern, no edition happens and gtk_widget_error_bell() is called. So, for example, given you have the pattern "^(\d){1,3}[a-z](\d){1,3}$" and the "123a4" text (which matches the regex): - deleting "a4" gives you a partial match - deleting "23" still gives you a match - deleting "a" won't be allowed, as "1234" doesn't match the pattern - deleting "3a" gives you a partial match
*** This bug has been marked as a duplicate of bug 50276 ***