Access - Field Validation Rule - Limit to 1 language - ms-access

I'm currently trying to place a validation rule on a text field which is supposed to contain several English words as well as numbers and no other languages or characters. I've tried setting the validation rule as:
Is Null or Not Like "*[!a-z]*"
Is Null or Not Like "*[!a-z0-9]*"
Is Null or Not Like "*[!a-z]*" Or Not Like "*[!0-9]*"
Which results in limiting the field to a either a null or a single word. As the field requires several words and numbers none of those solutions were appropriate. I've also tried simply removing the asterisk at the beginning of the block:
Is Null or Not Like "[!a-z]*"
This produces a result that is very close to what I need. However, some foreign (primarily Chinese) characters are showing up in the fields when data is imported.
Is there a reliable way to limit a field to only English words with numbers?

Your third approach is closest. Just add a space to your list of allowed characters:
Is Null or Not Like "*[!a-z0-9 ]*"
Note that character return and line feed characters are disallowed, so importing content with newline characters will fail.

Related

Create words based on input like "otb" into "bot"

I want to show a list of all words that can be created given a certain input. For this, I use all words that contain 12 characters.
I thought of SQL be able to see if letters are within a word. So jecobvizedti can become objectivized but if I would give jecobvizeti (without the d) it can also become objectivizes. This would also be the desired result.
Is there a way to let SQL determine which words match as they contain the characters of the input string. At first, I tried 12 separate fields and store 1 character into each field for the 12 character words. But that didn't make sense at all.
This is case-insensitive as I make sure the input is in lower case.
It should only support letters. No digits, spaces, or punctuation.
As for the performance, a max of 10 sec would be nice. I think SQL can manage that.
Edit: Solution of Ruud Helderman and the question linked doesn't work 100%. If I have the following letters: "beergtoltrot" it comes with a word that contains the letter "c" or with a word that contains the letter "v" which are not in the input string.
If you are doing this for a lot of words and you are not, for example saying that 'otb' should match 'brought'. That is you want exactly the same set of letters.
And how about getting the answer in a few milliseconds?
CREATE TABLE x (
sorted VARCHAR(12) NOT NULL,
real_word VARCHAR(12) NOT NULL,
PRIMARY KEY(real_word),
INDEX(sorted, real_word),
) ENGINE=InnoDB;
sorted contains the letters of real_word but rearranged in sorted order.
`sorted` => `real_word`
'bot' => 'bot' -- this happens to be in order to start with.
'bcdeeiijotvz' => 'objectivized'
'aest' => 'seat'
'aest' => 'teas'
'aest' => 'eats'
'aest' => 'east'
But... You must do this sorting in two places:
As you enter the data.
As you look up the data.
And it is best to do the sorting in your client code. The lookup in the single table a hundred thousand words will be very fast.
You can do this as:
where word like '%o%' and
word like '%b%' and
word like '%t%'
There are tricks for splitting an input string into individual characters. But if you can do this in the application, this shoudl work.

SQL RegEx to handle comma separated IDs

I have a string that denotes which users are allowed to access something. For instance, if user 1, user 2, and user 3 could access it, the accessibility column would contain 1,2,3. If only user 1 could access it, it would only be 1 and so forth.
I know I can't do a simple CONTAINS clause because searching for 1 could return true for 14,2,3. How would I get a regex to accommodate when there is a comma on both sides, on one side, or neither of the ID number?
Here is a sample of what I'm trying to do
DataID: 1
Accessibility: "1,2,3,4,5"
Data: "secret stuff"
DataID: 2
Accessibility: "5,6,7,8,9"
Data: "more secret stuff"
I need to tell the regex to search for a number and to make sure its at the beginning of the string and the end of the string if it has no commas around it, is at the beginning of the string if it only has a comma after it, is at the end of a string if it only has a comma before it, or if it commas on both sides that's fine because it's in the middle of the string.
I know what I need to do, but don't know how to achieve it. Thanks.
First, you have a really bad data structure for several reasons:
The proper way to store lists in SQL is using tables, not strings.
The proper way to store integers in SQL is as integers, not strings.
Ids should be defined with a proper foreign key relationship, which you cannot do when the id is stored in a string.
Sometimes, we are stuck with other people's bad design decisions. That is, we are unable to create a proper junction table, with one column for the DataId and each user who has access to it.
In that situation, you can use the find_in_set() functionality in MySQL. This does not require a regular expression. You can just write:
where find_in_set($user, accessibility) > 0
Since A-Z, 0-9, and underscore are considered word boundaries, you could generalize like this:
-- word-bound DataID, e.g. 1 becomes \b1\b
SELECT '\b' || DataID || '\b' AS DataID_Bound FROM USER
WHERE REGEX_LIKE(DataID_Bound, Accessibility)
That way it doesn't matter if there is a comma leading, trailing, or if it's a sole occupant of the search subject. But it deffinitely cannot match 14 or 21, etc. \b1\b will only match solo 1, \b14\b will only match whole word 14, etc.

Delete all characters before and after quotation marks

I have a CSV file, which has two columns and 4500 rows. In one column, I have several phrases that are surrounded in quotation marks. I need to delete all the text that comes before and after the quotations marks.
For example:
How would you say "Hello, my Friend" when speaking outside?
should become "Hello, my Friend"
I also have several rows that have the word NULL in the second column. I need these rows deleted in full.
What's the best way of doing something like this? I have been looking at regular expressions, but I'm not sure if they are flexible enough to do what I want to do, or how you would use them on a CSV file (I need the table structure to remain).
EDIT:
1) At the moment I am just using Apple Numbers, but I know that wont don't it, so I am happy to any suggestions. It must support Kanji characters.
2) I have removed all the NULL rows, so that is no longer needed (I simply added a column of numbers, sorted the table so all the NULLs were together, deleted them and the sorted back by the column of numbers).
Find a text editor that supports regular expression search and replace.
Something like this would match ,NULL in the second column: ^.*,NULL.*$. Replace it with "DELETEMEDELETEME" to mark the line, or as an empty string or find a way to have it match on `\n' or '\r' to catch the line break and remove the entire line completely.
Stripping out parts of the quoted string might work like this:
^(.*,){n}(.*)(\".\")(.*)(,.*)$ replaced with \1\3\5 where n is the number of columns preceding the one you want to edit. Repeat (.*,) if that's not available. It will depend on the regex flavor of your tool.

MYSQL SELECT LIKE "masks"

I'm using a field in a table to hold information about varios checkboxes (60).
The field is parsed to a string to something like this
"0,0,0,1,0,1,0,1,..."
Now I want to make a search using a similar string to match the fields. I.e.
"?,?,1,?,?,1,..."
where the "?" means that it must be 0 or 1 (doesn't matter), but the "1" must match.
As i've seen the '%' is somewhat innapropriate for this case, don't?
Obviosly both strings have the same lenght.
Suggestions?
You can use the underscore (_) character to match a single character in the mask.
Taken from MySQL documentation.

VBA Trim() function truncating text oddly!

I'm trying to trim extraneous white space at the end of a memo field in MS Access. I've tried doing it a number of ways:
1) an update query with the field being updated to Trim([fieldname]). For some reason, that doesn't do anything. The whitespace is still there.
2) an update using a Macro function in which the field contents are passed as a String and then processed using the Trim() function and passed back. This one is really bizarre, in that it seems to truncate the text in the field at completely random places (different for each record). Sometimes 366 characters, sometimes 312, sometimes 280.
3) same as above but with RTrim()
How can I possibly be messing up such a simple function?! Any help much appreciated. Would like to keep my hair.
-Sam
According to this article:
Both Text and Memo data types store only the characters entered in a field; space characters for unused positions in the field aren't stored.
As hypoxide suggested, they may not in fact be spaces
Edit
I suspect that the last character in the field is a carriage return or linefeed character. If this is the case, then Trim (or any variations of Trim - RTrim\LTrim) won't work since they only remove space characters. As 'onedaywhen' suggested in the comment, try using the ASC function to determine the actual character code of the last character in the memo field. You can use something like the following in a query to do this:
ASC(Right(MyFieldName,1))
Compare the result of the query to the Character Set to determine the actual character that ends the memo field. (Space = 32, Linefeed = 10, Carriage Return = 13).
You may have to test the last character and if it is a linefeed or carriage return remove the character and then apply the trim function to the rest of the string.
This may date me, but does Access have different character types for fixed vs. variable lengths? in SQL, CHAR(10) will always by 10 chars long, padded if necessary, while VARCHAR(10) will be 'the' size up to 10. Truncating a CHAR(10) will just put the blanks back.